Class: Lab42::Function

Inherits:
Object
  • Object
show all
Extended by:
Constructors
Defined in:
lib/lab42/function.rb,
lib/lab42/function/version.rb,
lib/lab42/function/constructors.rb,
lib/lab42/function/make_function.rb

Overview

Implementation of the isolated functional behavior

- Partials
- Chaining

Defined Under Namespace

Modules: Constructors, MakeFunction, My, ParamsReorderer Classes: Placeholder

Constant Summary collapse

VERSION =
'0.1.1'

Constants included from Constructors

Constructors::R

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Constructors

a1, a2, a3, constant, force_pipe, free_receiver, partial, placeholder

Constructor Details

#initialize(behavior, arity = -1) ⇒ Function

Returns a new instance of Function.



28
29
30
31
# File 'lib/lab42/function.rb', line 28

def initialize behavior, arity=-1
  @behavior = behavior
  @arity    = arity
end

Instance Attribute Details

#arityObject (readonly)

Returns the value of attribute arity.



18
19
20
# File 'lib/lab42/function.rb', line 18

def arity
  @arity
end

#behaviorObject (readonly)

Returns the value of attribute behavior.



18
19
20
# File 'lib/lab42/function.rb', line 18

def behavior
  @behavior
end

Instance Method Details

#call(*second_stage_params) ⇒ Object



33
34
35
# File 'lib/lab42/function.rb', line 33

def call *second_stage_params
  behavior.(*second_stage_params)
end

#|(rhs) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/lab42/function.rb', line 20

def | rhs
  return call if rhs == self.class.force_pipe
  rhs = MakeFunction.make_function rhs
  self.class.new ->{
    rhs.call(self.call)
  }
end