Sha256: 294ab92729791259722e0c34ee6d1896619d62251b9a031e6e1d7cc5247fdc00
Contents?: true
Size: 961 Bytes
Versions: 1
Compression:
Stored size: 961 Bytes
Contents
# frozen_string_literal: true module Fear # @api private class PartialFunctionClass include PartialFunction # @param condition [#call] describes the domain of partial function # @param function [Proc] function definition def initialize(condition, &function) @condition = condition @function = function end attr_reader :condition, :function private :condition private :function # @param arg [any] # @return [any] Calls this partial function with the given argument when it # is contained in the function domain. # @raise [MatchError] when this partial function is not defined. def call(arg) call_or_else(arg, &PartialFunction::Empty) end # @param arg [any] # @yield [arg] if function not defined def call_or_else(arg) if defined_at?(arg) function.(arg) else yield arg end end end private_constant :PartialFunctionClass end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
fear-3.0.0 | lib/fear/partial_function_class.rb |