Sha256: b691825ee6180e9d8675644f5cd0e37cb2eeef33c5879332698a211528e8a1c9

Contents?: true

Size: 687 Bytes

Versions: 8

Compression:

Stored size: 687 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(value)
    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

8 entries across 8 versions & 1 rubygems

Version Path
kind-5.10.0 lib/kind/result/failure.rb
kind-5.9.0 lib/kind/result/failure.rb
kind-5.8.1 lib/kind/result/failure.rb
kind-5.8.0 lib/kind/result/failure.rb
kind-5.7.0 lib/kind/result/failure.rb
kind-5.6.0 lib/kind/result/failure.rb
kind-5.5.0 lib/kind/result/failure.rb
kind-5.4.1 lib/kind/result/failure.rb