lib/rumonade/array.rb in rumonade-0.1.1 vs lib/rumonade/array.rb in rumonade-0.1.2

- old
+ new

@@ -1,8 +1,9 @@ require 'rumonade/monad' module Rumonade + # TODO: Document use of Array as a Monad module ArrayExtensions module ClassMethods def unit(value) [value] end @@ -12,11 +13,10 @@ end end module InstanceMethods def bind(lam = nil, &blk) - f = lam || blk - inject([]) { |arr, elt| arr + f.call(elt).to_a } + inject(self.class.empty) { |arr, elt| arr + (lam || blk).call(elt).to_a } end end end end