module Aqueductron::Buildering

Public Instance Methods

answer(monoid) click to toggle source
# File lib/aqueductron/buildering.rb, line 12
def answer(monoid)
  answer_int(EndPiece.new(monoid))
end
array() click to toggle source
# File lib/aqueductron/buildering.rb, line 20
def array
  answer_int(ArrayEndPiece.new)
end
count() click to toggle source
# File lib/aqueductron/buildering.rb, line 16
def count
  answer_int(CountingEndPiece.new)
end
custom(piece) click to toggle source
# File lib/aqueductron/buildering.rb, line 36
def custom(piece)
   attach(piece)
end
expand(transform) click to toggle source
# File lib/aqueductron/buildering.rb, line 40
def expand(transform)
  attach(expand_function(transform))
end
expand_function(expansion) click to toggle source
# File lib/aqueductron/buildering.rb, line 68
def expand_function(expansion)
  ->(piece, msg) do
    next_piece = Inlet.new(piece.destination, :not_done).flow(expansion.call(msg))
    Piece.new(next_piece, expand_function(expansion))
  end
end
filter_function(predicate) click to toggle source
# File lib/aqueductron/buildering.rb, line 81
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
keeping(predicate) click to toggle source
# File lib/aqueductron/buildering.rb, line 28
def keeping(predicate)
  attach(filter_function(predicate))
end
last() click to toggle source
# File lib/aqueductron/buildering.rb, line 52
def last
  answer_int(LastEndPiece.new)
end
map_function(transform) click to toggle source
# File lib/aqueductron/buildering.rb, line 75
def map_function(transform)
  ->(piece, msg) do
    piece.pass_on(transform.call(msg), map_function(transform))
  end
end
partition(categorize, make_new_path) click to toggle source
# File lib/aqueductron/buildering.rb, line 48
def partition(categorize, make_new_path)
  answer_int(SpontaneousJointPiece.new({}, categorize, make_new_path))
end
split(paths) click to toggle source
# File lib/aqueductron/buildering.rb, line 44
def split(paths)
  answer_int(JointPiece.new(paths))
end
take(how_many) click to toggle source
# File lib/aqueductron/buildering.rb, line 24
def take(how_many)
  attach(take_function(how_many))
end
take_function(how_many) click to toggle source
# File lib/aqueductron/buildering.rb, line 57
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
      how_many_more = how_many - 1
      piece.pass_on(msg, take_function(how_many_more), "taking #{how_many_more}")
    end
  end
end
through(transform) click to toggle source
# File lib/aqueductron/buildering.rb, line 32
def through(transform)
  attach(map_function(transform))
end