Sha256: 0bcb77cb554444ff59f573c380ba232ea2d61076cd0d74d24b8a6fb334b8dcc4

Contents?: true

Size: 563 Bytes

Versions: 5

Compression:

Stored size: 563 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
      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

5 entries across 5 versions & 1 rubygems

Version Path
rumonade-0.3.0 lib/rumonade/array.rb
rumonade-0.2.2 lib/rumonade/array.rb
rumonade-0.2.1 lib/rumonade/array.rb
rumonade-0.2.0 lib/rumonade/array.rb
rumonade-0.1.2 lib/rumonade/array.rb