Class: Enumerator::Parallel

Inherits:
Object
  • Object
show all
Defined in:
lib/enumerator-parallel.rb

Instance Method Summary collapse

Constructor Details

#initialize(enum, options) ⇒ Parallel

Returns a new instance of Parallel.



12
13
14
15
# File 'lib/enumerator-parallel.rb', line 12

def initialize(enum, options)
  mappings = { processes: :in_processes, threads: :in_threads }
  @enum, @options = enum.to_a, Hash[options.map { |k, v| [(mappings[k] || k), v] }]
end

Instance Method Details

#all?(&block) ⇒ Boolean

Returns:



25
26
27
# File 'lib/enumerator-parallel.rb', line 25

def all?(&block)
  map(&block).all?
end

#any?(&block) ⇒ Boolean

Returns:



29
30
31
# File 'lib/enumerator-parallel.rb', line 29

def any?(&block)
  map(&block).any?
end

#count(&block) ⇒ Object



40
41
42
# File 'lib/enumerator-parallel.rb', line 40

def count(&block)
  map(&block).count(true)
end

#each(&block) ⇒ Object



17
18
19
# File 'lib/enumerator-parallel.rb', line 17

def each(&block)
  ::Parallel.each(@enum, @options, &block)
end

#map(&block) ⇒ Object



21
22
23
# File 'lib/enumerator-parallel.rb', line 21

def map(&block)
  ::Parallel.map(@enum, @options, &block)
end