module Teamsupport::Utils

Public Instance Methods

flat_pmap(enumerable) click to toggle source

Returns new array with concatenated results of running block for every element

@param enumerable [Enumerable]

@return [Array, Enumerator]

@api private

# File lib/teamsupport/utils.rb, line 12
def flat_pmap(enumerable)
  return to_enum(:flat_pmap, enumerable) unless block_given?
  pmap(enumerable, &Proc.new).flatten(1)
end
pmap(enumerable) { |object| ... } click to toggle source

Returns new array with the results of running block once for every element

@param enumerable [Enumerable]

@return [Array, Enumerator]

@api private

# File lib/teamsupport/utils.rb, line 24
def pmap(enumerable)
  return to_enum(:pmap, enumerable) unless block_given?
  if enumerable.count == 1
    enumerable.collect { |object| yield(object) }
  else
    enumerable.collect { |object| Thread.new { yield(object) } }.collect(&:value)
  end
end