module Enumerable(T)

Overview

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

Direct including types

Defined in:

parallel/enumerable.cr

Instance Method Summary

Instance Method Detail

def par_each(execution_context : Fiber::ExecutionContext::MultiThreaded | 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 but maintains fail-fast behavior

[1, 2, 3].par_each { |x| puts x }
[1, 2, 3, 4].par_each(chunk: 2) { |x| puts x } # same result, fewer context switches

[View source]
def par_map(execution_context : Fiber::ExecutionContext::MultiThreaded | 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 but maintains fail-fast behavior

[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)

[View source]