module Fluxite

Defined in:

fluxite.cr
fluxite/cord.cr
fluxite/pipeout.cr
fluxite/unit.cr

Constant Summary

VERSION = "0.1.0"

Class Method Summary

Macro Summary

Class Method Detail

def self.[](unit, object) : Nil #

A shorthand for .pass.

Fluxite[xs, 100] # Same as Fluxite.pass(xs, 100)

[View source]
def self.[](unit, *objects) : Nil #

A shorthand for .passall.

Fluxite[xs, 1, 2, 3] # Same as Fluxite.passall(xs, 1, 2, 3)

[View source]
def self.join(*units) #

Combines the emission of one or more units into a single unit whose output's type is a union of output types of units.

xs = Fluxite::Port(Int32).new
ys = Fluxite::Port(Int32).new
zs = Fluxite::Port(Int32).new

Fluxite.join(xs, ys, zs)
  .select(&.even?)
  .each { |n| p! n }

Fluxite[xs, 100]
Fluxite[xs, 101]
Fluxite[ys, 102]
Fluxite[ys, 103]
Fluxite[zs, 104]
Fluxite[zs, 105]

# STDOUT:
#   n # => 100
#   n # => 102
#   n # => 104

[View source]
def self.pass(unit, object) : Nil #

Feeds object to unit.

The main loop resides here, that is responsible for propagating messages in breadth-first manner.

Try to avoid calling this method recursively. Instead, consider using IPipeout#into, or IPipeout#forward with its Forward::Feed.

xs = Fluxite::Port(Int32).new
xs.select(&.even?).each { |x| p! x }

Fluxite.pass(xs, 100)
Fluxite.pass(xs, 101)
Fluxite.pass(xs, 102)

# STDOUT:
#   x # => 100
#   x # => 102

[View source]
def self.passall(unit, objects : Enumerable) : Nil #

Passes multiple objects to unit simultaneously.

All of objects are handled in a single swoop, retaining level-by-level/ breadth-first approach vs. the depth-first approach relative to objects as a whole if one did multiple consecutive calls to .pass.

xs = Fluxite::Port(Int32).new
xs.select(&.even?).each { |x| p! x }

Fluxite.passall(xs, [101, 102, 103])

# STDOUT:
#   x # => 100
#   x # => 102

[View source]
def self.passall(unit, *objects) : Nil #

Passes multiple objects to unit simultaneously, listing them immediately in the arguments.

See .passall.

Fluxite.passall(xs, 1, 2, 3) # Same as Fluxite.passall(xs, {1, 2, 3})

[View source]

Macro Detail

macro has_fanout(cls) #

[View source]
macro port(intype, &block) #

Creates a port P and yields it to the block. The block may attach units to the port. Returns the port P.

If the block is absent simply creates and returns the port P.

xs = Fluxite.port(Int32, &.squash.map(&.even?).each { |n| p! n })

Fluxite[xs, 100]
Fluxite[xs, 100]
Fluxite[xs, 101]
Fluxite[xs, 102]
Fluxite[xs, 104]

# STDOUT:
#   n # => 100
#   n # => 102
#   n # => 104

[View source]