Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add map block with examples

  • Loading branch information...
commit 034434bc98a9b9cf31545228e2cb315621d1fcc7 1 parent ed0488d
@bry4n authored
Showing with 11 additions and 2 deletions.
  1. +11 −2 lib/parallel2.rb
View
13 lib/parallel2.rb
@@ -5,18 +5,27 @@ class Parallel
def self.each(collection, &block)
klass = new(collection, &block)
- klass.parallelized_each(&block)
+ klass.parallelized_each
collection
end
+ def self.map(collection, &block)
+ klass = new(collection, &block)
+ klass.parallelized_map
+ end
+
def initialize(collection, &block)
@collection = collection
@block = block
end
- def parallelized_each(&block)
+ def parallelized_each
futures.each(&:value)
end
+
+ def parallelized_map
+ futures.map(&:value)
+ end
def futures
@futures ||= @collection.map do |item|
Please sign in to comment.
Something went wrong with that request. Please try again.