Sha256: a7a1926897a98d4671c913d1e31320232272f8859fdd7f454627a1ceab5346c6

Contents?: true

Size: 1.1 KB

Versions: 10

Compression:

Stored size: 1.1 KB

Contents

module Fear
  class Right
    include Either
    include RightBiased::Right

    # @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_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

10 entries across 10 versions & 1 rubygems

Version Path
fear-0.10.0 lib/fear/right.rb
fear-0.9.0 lib/fear/right.rb
fear-0.8.0 lib/fear/right.rb
fear-0.7.0 lib/fear/right.rb
fear-0.6.0 lib/fear/right.rb
fear-0.5.0 lib/fear/right.rb
fear-0.4.2 lib/fear/right.rb
fear-0.4.1 lib/fear/right.rb
fear-0.4.0 lib/fear/right.rb
fear-0.3.0 lib/fear/right.rb