Sha256: cd2ec51a5991abdad6cf656258f6c986638f380421e19244daf11c3df61690fc

Contents?: true

Size: 1.2 KB

Versions: 1

Compression:

Stored size: 1.2 KB

Contents

module Fear
  class Right
    include Either
    include RightBiased::Right
    include RightPatternMatch.mixin

    # @api private
    def right_value
      value
    end

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

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

    # @param default [Proc, any]
    # @return [Either]
    def select_or_else(default)
      if yield(value)
        self
      else
        Left.new(Utils.return_or_call_proc(default))
      end
    end

    # @return [Either]
    def select
      if yield(value)
        self
      else
        Left.new(value)
      end
    end

    # @return [Either]
    def reject
      if yield(value)
        Left.new(value)
      else
        self
      end
    end

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

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

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

    # @return [self]
    def join_left
      self
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fear-0.11.0 lib/fear/right.rb