module

Enumerable(T)

Extension for Enumerable types (Array, Hash, Set, Range, etc.)

Instance methods

par_each(execution_context : Fiber::ExecutionContext::Parallel | Nil = nil, *, chunk : Int32 | Nil = nil, &block : T -> _)

Parallel each operation Applies the given block to each element in parallel (no return value) Uses robust error handling internally and propagates exceptions

[1, 2, 3].par_each { |x| puts x }
[1, 2, 3, 4].par_each(chunk: 2) { |x| puts x } # same result, fewer context switches
Source
par_map(execution_context : Fiber::ExecutionContext::Parallel | Nil = nil, *, chunk : Int32 | Nil = nil, &block : T -> U) forall U

Parallel map operation Applies the given block to each element in parallel and returns an array of results Uses lazy evaluation to avoid creating intermediate arrays for memory efficiency Uses robust error handling internally and propagates exceptions

[1, 2, 3, 4].par_map { |x| x * 2 }           # => [2, 4, 6, 8]
[1, 2, 3, 4].par_map(chunk: 2) { |x| x * 2 } # => [2, 4, 6, 8] (same result, fewer context switches)
Source