Sha256: c50582312a11cdaf28fd926d7f6b48df79c6c3263ebb7eb7ec674b9290ec7765

Contents?: true

Size: 1.01 KB

Versions: 1

Compression:

Stored size: 1.01 KB

Contents

module Option
  module Enumerable
    include ::Enumerable

    def to_ary
      to_a
    end

    def flatten
      from_array to_ary.flatten
    end

    def juxt(*methods)
      map { |v| methods.map { |m| v.send(m) } }
    end

    def map_through(*methods)
      map &methods.reduce(lambda { |x| x}) { |acc, m| lambda { |x| acc.call(x).send(m) } }
    end

    def map
      from_array super
    end
    alias_method :collect, :map
    alias_method :collect_concat, :map

    def flat_map(&block)
      map(&block).flatten
    end

    def detect
      from_value super
    end
    alias_method :find, :detect

    def select
      from_array super
    end
    alias_method :find_all, :select

    def grep(value)
      from_array super
    end

    def reject(*args, &block)
      from_array to_a.reject(*args, &block)
    end

    def reduce(*args, &block)
      if none? && (args.size < 1 || args.size < 2 && block.nil?)
        raise ValueOfNoneError
      end
      super
    end
    alias_method :inject, :reduce
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
optional-0.0.7 lib/optional/option/enumerable.rb