Class: Mayak::Function
- Inherits:
-
Object
- Object
- Mayak::Function
- 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
-
#blk ⇒ Object
readonly
Returns the value of attribute blk.
Class Method Summary collapse
Instance Method Summary collapse
- #and_then(another) ⇒ Object (also: #>>)
- #call(input) ⇒ Object
- #compose(another) ⇒ Object (also: #<<)
-
#initialize(&blk) ⇒ Function
constructor
A new instance of Function.
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
#blk ⇒ Object (readonly)
Returns the value of attribute blk.
14 15 16 |
# File 'lib/mayak/function.rb', line 14 def blk @blk end |
Class Method Details
.from_proc(proc) ⇒ Object
31 32 33 |
# File 'lib/mayak/function.rb', line 31 def self.from_proc(proc) ::Mayak::Function[T.type_parameter(:Input), T.type_parameter(:Output)].new { |input| proc.call(input) } end |
Instance Method Details
#and_then(another) ⇒ Object Also known as: >>
45 46 47 |
# File 'lib/mayak/function.rb', line 45 def and_then(another) Mayak::Function[Input, T.type_parameter(:Output2)].new { |a| another.call(blk.call(a)) } end |
#call(input) ⇒ Object
36 37 38 |
# File 'lib/mayak/function.rb', line 36 def call(input) blk.call(input) end |
#compose(another) ⇒ Object Also known as: <<
55 56 57 |
# File 'lib/mayak/function.rb', line 55 def compose(another) Mayak::Function[T.type_parameter(:Input2), Output].new { |a| blk.call(another.call(a)) } end |