Sha256: 313be207725d2c0004fccce13f45c9bd0b1a06e02aa045f9014a35c34c440248

Contents?: true

Size: 608 Bytes

Versions: 1

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

1 entries across 1 versions & 1 rubygems

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