Class: Fear::PartialFunction::Combined Private

Inherits:
Object
  • Object
show all
Includes:
Fear::PartialFunction
Defined in:
lib/fear/partial_function/combined.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Composite function produced by PartialFunction#and_then method

Constant Summary

Constants included from Fear::PartialFunction

EMPTY

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Fear::PartialFunction

#&, and, #and_then, #condition, #function, #lift, or, #or_else, #to_proc, #|

Constructor Details

#initialize(f1, f2) ⇒ Combined

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Combined


12
13
14
15
# File 'lib/fear/partial_function/combined.rb', line 12

def initialize(f1, f2)
  @f1 = f1
  @f2 = f2
end

Instance Attribute Details

#f1=(value) ⇒ Fear::PartialFunction


20
21
22
# File 'lib/fear/partial_function/combined.rb', line 20

def f1
  @f1
end

#f2=(value) ⇒ Fear::PartialFunction


20
# File 'lib/fear/partial_function/combined.rb', line 20

attr_reader :f1, :f2

Instance Method Details

#call(arg) ⇒ any Also known as: ===, []

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


26
27
28
# File 'lib/fear/partial_function/combined.rb', line 26

def call(arg)
  f2.(f1.(arg))
end

#call_or_else(arg) {|arg| ... } ⇒ any

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Yield Parameters:

  • arg (any)

36
37
38
39
# File 'lib/fear/partial_function/combined.rb', line 36

def call_or_else(arg)
  result = f1.call_or_else(arg) { return yield(arg) }
  f2.call_or_else(result) { |_| return yield(arg) }
end

#defined_at?(arg) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


43
44
45
46
47
48
# File 'lib/fear/partial_function/combined.rb', line 43

def defined_at?(arg)
  result = f1.call_or_else(arg) do
    return false
  end
  f2.defined_at?(result)
end