Sha256: 391faad3a18b85da2712b96f45c8545d6fb3c275fc8e6a32369d7e9ca1e1d9df

Contents?: true

Size: 578 Bytes

Versions: 1

Compression:

Stored size: 578 Bytes

Contents

module Fear
  # Use singleton version of EmptyPartialFunction -- PartialFunction::EMPTY
  # @api private
  module 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

1 entries across 1 versions & 1 rubygems

Version Path
fear-0.11.0 lib/fear/empty_partial_function.rb