Sha256: 462f12b8d2bcaf7441b20b0a75acd88e60402cf2003649404b1e3aa9300e77d6

Contents?: true

Size: 608 Bytes

Versions: 4

Compression:

Stored size: 608 Bytes

Contents

# frozen_string_literal: true

module Fear
  # Use singleton version of EmptyPartialFunction -- PartialFunction::EMPTY
  # @api private
  class EmptyPartialFunction
    include PartialFunction

    def defined_at?(_)
      false
    end

    def call(arg)
      raise MatchError, "partial function not defined at: #{arg}"
    end

    alias === call
    alias [] call

    def call_or_else(arg)
      yield arg
    end

    def or_else(other)
      other
    end

    def and_then(*)
      self
    end

    def to_s
      "Empty partial function"
    end
  end

  private_constant :EmptyPartialFunction
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
fear-2.0.1 lib/fear/empty_partial_function.rb
fear-2.0.0 lib/fear/empty_partial_function.rb
fear-1.2.0 lib/fear/empty_partial_function.rb
fear-1.1.0 lib/fear/empty_partial_function.rb