Sha256: 7653733daa77c14338cbfcd11641ca9668c306fc04f1ee6c791d52a55e55bfb9

Contents?: true

Size: 1.01 KB

Versions: 7

Compression:

Stored size: 1.01 KB

Contents

module Fear
  class Left
    include Either
    include RightBiased::Left

    # @return [false]
    def right?
      false
    end
    alias success? right?

    # @return [true]
    def left?
      true
    end
    alias failure? left?

    # @return [Either]
    def select_or_else(*)
      self
    end

    # @return [Left]
    def select
      self
    end

    # @return [Left]
    def reject
      self
    end

    # @return [Right] value in `Right`
    def swap
      Right.new(value)
    end

    # @param reduce_left [Proc]
    # @return [any]
    def reduce(reduce_left, _)
      reduce_left.call(value)
    end

    # @return [self]
    def join_right
      self
    end

    # @return [Either]
    # @raise [TypeError]
    def join_left
      value.tap do |v|
        Utils.assert_type!(v, Either)
      end
    end

    # Used in case statement
    # @param other [any]
    # @return [Boolean]
    def ===(other)
      if other.is_a?(Left)
        value === other.value
      else
        super
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
fear-0.10.0 lib/fear/left.rb
fear-0.9.0 lib/fear/left.rb
fear-0.8.0 lib/fear/left.rb
fear-0.7.0 lib/fear/left.rb
fear-0.6.0 lib/fear/left.rb
fear-0.5.0 lib/fear/left.rb
fear-0.4.2 lib/fear/left.rb