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.



10
11
12
13
# File 'lib/fear/partial_function/combined.rb', line 10

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

Instance Attribute Details

#f1=(value) ⇒ Fear::PartialFunction



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

def f1
  @f1
end

#f2=(value) ⇒ Fear::PartialFunction



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

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.

Parameters:

  • arg (any)

Returns:

  • (any)


24
25
26
# File 'lib/fear/partial_function/combined.rb', line 24

def call(arg)
  f2.call(f1.call(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.

Parameters:

  • arg (any)

Yield Parameters:

  • arg (any)

Returns:

  • (any)


34
35
36
37
# File 'lib/fear/partial_function/combined.rb', line 34

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.

Parameters:

  • arg (any)

Returns:

  • (Boolean)


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

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