Class: Mayak::Function

Inherits:
Object
  • Object
show all
Extended by:
T::Generic, T::Helpers, T::Sig
Defined in:
lib/mayak/function.rb

Constant Summary collapse

Input =
type_member
Output =
type_member

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(&blk) ⇒ Function

Returns a new instance of Function.



17
18
19
# File 'lib/mayak/function.rb', line 17

def initialize(&blk)
  @blk = T.let(blk, T.proc.params(input: Input).returns(Output))
end

Instance Attribute Details

#blkObject (readonly)

Returns the value of attribute blk.



14
15
16
# File 'lib/mayak/function.rb', line 14

def blk
  @blk
end

Instance Method Details

#and_then(another) ⇒ Object Also known as: >>



31
32
33
# File 'lib/mayak/function.rb', line 31

def and_then(another)
  Mayak::Function[Input, T.type_parameter(:Output2)].new { |a| another.call(blk.call(a)) }
end

#call(input) ⇒ Object



22
23
24
# File 'lib/mayak/function.rb', line 22

def call(input)
  blk.call(input)
end

#compose(another) ⇒ Object Also known as: <<



41
42
43
# File 'lib/mayak/function.rb', line 41

def compose(another)
  Mayak::Function[T.type_parameter(:Input2), Output].new { |a| blk.call(another.call(a)) }
end