<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>Rakefile</filename>
    </added>
    <added>
      <filename>test/peach_test.rb</filename>
    </added>
    <added>
      <filename>test/test_helper.rb</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -1,32 +1,37 @@
-class Array
+module Peach
   def peach(n = nil, &amp;b)
-    peachrun(:each, b, n)
+    peach_run(:each, b, n)
   end
+
   def pmap(n = nil, &amp;b)
-    peachrun(:map, b, n)
+    peach_run(:map, b, n)
   end
-  def pdelete_if(n = nil, &amp;b)
-    peachrun(:delete_if, b, n)
+
+  def pselect(n = nil, &amp;b)
+    peach_run(:select, b, n)
   end
 
+
+
   protected
-  def peachrun(meth, b, n = nil)
+  def peach_run(meth, b, n = nil)
     threads, results, result = [],[],[]
-    divvy(n).each_with_index do |x,i|
-      if x.size &gt; 0
-        threads &lt;&lt; Thread.new { results[i] = x.send(meth, &amp;b)}
-      else
-        results[i] = []
-      end
+    peach_divvy(n).each_with_index do |x,i|
+      threads &lt;&lt; Thread.new { results[i] = x.send(meth, &amp;b)}
     end
     threads.each {|t| t.join }
     results.each {|x| result += x if x}
     result
   end
   
-  def divvy(n = nil)
+  def peach_divvy(n = nil)
+    return [] if size == 0
+
     n ||= $peach_default_threads || size
+    n = size if n &gt; size
+
     lists = []
+
     div = (size/n).floor
     offset = 0
     for i in (0...n-1)
@@ -37,3 +42,5 @@ class Array
     lists
   end
 end
+
+Array.send(:include, Peach)</diff>
      <filename>lib/peach.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>0083989fc951b3fbccd6cc50c19199089ea1a64d</id>
    </parent>
  </parents>
  <author>
    <name>Ben Hughes</name>
    <email>ben@pixelmachine.org</email>
  </author>
  <url>http://github.com/schleyfox/peach/commit/7b43f10a4c37be9e8dbc108250f21cc0eeb17998</url>
  <id>7b43f10a4c37be9e8dbc108250f21cc0eeb17998</id>
  <committed-date>2009-04-02T23:32:34-07:00</committed-date>
  <authored-date>2009-04-02T23:32:34-07:00</authored-date>
  <message>Added tests, fixed a few potential bugs, cleaned up code</message>
  <tree>dc7806ed501a9996077eca9843d0481efd8aec2a</tree>
  <committer>
    <name>Ben Hughes</name>
    <email>ben@pixelmachine.org</email>
  </committer>
</commit>
