Sha256: d392f4cce90e18554828d6ee438d6ae23e5b0158c0f208769f52f9ce1b98e55c

Contents?: true

Size: 776 Bytes

Versions: 1

Compression:

Stored size: 776 Bytes

Contents

module Fear
  class Some
    include Option
    include Dry::Equalizer(:get)
    include RightBiased::Right

    attr_reader :value
    protected :value

    def initialize(value)
      @value = value
    end

    # @return option's value
    def get
      @value
    end

    # @return [Option] self if this `Option` is nonempty and
    #   applying the `predicate` to this option's value
    #   returns true. Otherwise, return `None`.
    #
    def detect
      if yield(value)
        self
      else
        None.new
      end
    end

    # @return [Option] if applying the `predicate` to this
    #   option's value returns false. Otherwise, return `None`.
    #
    def reject
      if yield(value)
        None.new
      else
        self
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fear-0.0.1 lib/fear/some.rb