Module: Aqueductron::Buildering
- Included in:
- Duct
- Defined in:
- lib/aqueductron/buildering.rb
Class Method Summary collapse
- .expand_function(expansion) ⇒ Object
- .filter_function(predicate) ⇒ Object
- .map_function(transform) ⇒ Object
-
.take_function(how_many) ⇒ Object
this will either return a Result or a Piece.
Instance Method Summary collapse
- #answer(monoid) ⇒ Object
- #count ⇒ Object
- #custom(piece) ⇒ Object
- #expand(transform) ⇒ Object
- #keeping(predicate) ⇒ Object
- #last ⇒ Object
- #partition(categorize, make_new_path) ⇒ Object
- #split(paths) ⇒ Object
- #take(how_many) ⇒ Object
- #through(transform) ⇒ Object
Class Method Details
.expand_function(expansion) ⇒ Object
62 63 64 65 66 67 |
# File 'lib/aqueductron/buildering.rb', line 62 def (expansion) ->(piece, msg) do next_piece = Inlet.new(piece.destination, :not_done).flow(expansion.call(msg)) Piece.new(next_piece, (expansion)) end end |
.filter_function(predicate) ⇒ Object
75 76 77 78 79 80 81 82 83 |
# File 'lib/aqueductron/buildering.rb', line 75 def filter_function(predicate) ->(piece, msg) do if(predicate.call(msg)) then piece.pass_on(msg, filter_function(predicate)) else piece #don't change end end end |
.map_function(transform) ⇒ Object
69 70 71 72 73 |
# File 'lib/aqueductron/buildering.rb', line 69 def map_function(transform) ->(piece, msg) do piece.pass_on(transform.call(msg), map_function(transform)) end end |
.take_function(how_many) ⇒ Object
this will either return a Result or a Piece
52 53 54 55 56 57 58 59 60 |
# File 'lib/aqueductron/buildering.rb', line 52 def take_function(how_many) # this will either return a Result or a Piece what_to_do = ->(piece, msg) do if (how_many == 0) then # this is a little inefficient. One extra piece of info will be read piece.send_eof else piece.pass_on(msg, take_function(how_many -1)) end end end |
Instance Method Details
#answer(monoid) ⇒ Object
11 12 13 |
# File 'lib/aqueductron/buildering.rb', line 11 def answer(monoid) answer_int(EndPiece.new(monoid)) end |
#count ⇒ Object
15 16 17 |
# File 'lib/aqueductron/buildering.rb', line 15 def count answer_int(CountingEndPiece.new) end |
#custom(piece) ⇒ Object
31 32 33 |
# File 'lib/aqueductron/buildering.rb', line 31 def custom(piece) attach(piece) end |
#expand(transform) ⇒ Object
35 36 37 |
# File 'lib/aqueductron/buildering.rb', line 35 def (transform) attach((transform)) end |
#keeping(predicate) ⇒ Object
23 24 25 |
# File 'lib/aqueductron/buildering.rb', line 23 def keeping(predicate) attach(filter_function(predicate)) end |
#last ⇒ Object
47 48 49 |
# File 'lib/aqueductron/buildering.rb', line 47 def last answer_int(LastEndPiece.new) end |
#partition(categorize, make_new_path) ⇒ Object
43 44 45 |
# File 'lib/aqueductron/buildering.rb', line 43 def partition(categorize, make_new_path) answer_int(SpontaneousJointPiece.new({}, categorize, make_new_path)) end |
#split(paths) ⇒ Object
39 40 41 |
# File 'lib/aqueductron/buildering.rb', line 39 def split(paths) answer_int(JointPiece.new(paths)) end |
#take(how_many) ⇒ Object
19 20 21 |
# File 'lib/aqueductron/buildering.rb', line 19 def take(how_many) attach(take_function(how_many)) end |
#through(transform) ⇒ Object
27 28 29 |
# File 'lib/aqueductron/buildering.rb', line 27 def through(transform) attach(map_function(transform)) end |