Sha256: 8e358549c4579addc0b75dcd34970f16735f3ff86447b2a4d9545a6b441ab256

Contents?: true

Size: 1 KB

Versions: 1

Compression:

Stored size: 1 KB

Contents

# frozen_string_literal: true

module Kind
  module Maybe
    class None < Monad
      def value_or(default = UNDEFINED, &block)
        Error.invalid_default_arg! if UNDEFINED == default && !block

        UNDEFINED != default ? default : block.call
      end

      def none?; true; end

      def map(_method_name = UNDEFINED, &fn)
        self
      end

      alias_method :map!, :map
      alias_method :then, :map
      alias_method :then!, :map
      alias_method :check, :map
      alias_method :accept, :map
      alias_method :reject, :map
      alias_method :and_then, :map
      alias_method :and_then!, :map!

      def try!(method_name = UNDEFINED, *args, &block)
        KIND.of!(::Symbol, method_name)if UNDEFINED != method_name

        self
      end

      alias_method :try, :try!

      def dig(*keys)
        self
      end

      def presence
        self
      end

      def inspect
        '#<%s value=%s>' % ['Kind::None', value.inspect]
      end
    end

    NONE_INSTANCE = None.new(nil)
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
kind-5.2.0 lib/kind/maybe/none.rb