Sha256: bf2c0da173ea637697e3c75bd5f9291b87b904902b6d94e0d45bf8d134818f9f

Contents?: true

Size: 680 Bytes

Versions: 2

Compression:

Stored size: 680 Bytes

Contents

# frozen_string_literal: true

module Kind
  class Result::Failure < Result::Monad
    DEFAULT_TYPE = :error

    def failure?
      true
    end

    def value_or(default = UNDEFINED, &block)
      Error.invalid_default_arg! if UNDEFINED == default && !block

      UNDEFINED != default ? default : block.call
    end

    def map(_ = UNDEFINED, &_fn)
      self
    end

    alias_method :|, :map
    alias_method :>>, :map
    alias_method :map!, :map
    alias_method :then, :map
    alias_method :then!, :map
    alias_method :and_then, :map
    alias_method :and_then!, :map

    def inspect
      '#<%s type=%p value=%p>' % ['Kind::Failure', type, value]
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
kind-5.4.0 lib/kind/result/failure.rb
kind-5.3.0 lib/kind/result/failure.rb