Sha256: f02bf51e3269190b3c3694b6fd32ce196f15559ef47015a6adfd39348c15a505
Contents?: true
Size: 729 Bytes
Versions: 1
Compression:
Stored size: 729 Bytes
Contents
require 'rumonade/monad' module Rumonade # TODO: Document use of Array as a Monad module ArrayExtensions module ClassMethods def unit(value) [value] end def empty [] end end module InstanceMethods # Preserve native +map+ and +flat_map+ methods for performance, # and +flatten+ to support Rails (see issue #8) METHODS_TO_REPLACE_WITH_MONAD = [] def bind(lam = nil, &blk) inject(self.class.empty) { |arr, elt| arr + (lam || blk).call(elt).to_a } end end end end Array.send(:extend, Rumonade::ArrayExtensions::ClassMethods) Array.send(:include, Rumonade::ArrayExtensions::InstanceMethods) Array.send(:include, Rumonade::Monad)
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
rumonade-0.4.4 | lib/rumonade/array.rb |