3 Defining Ebb Stream Forms
| (require ebb/define) | package: ebb-lib |
This module contains the syntaxes for defining custom stream producers, transformers and consumers. Also the possibility to alias their names is provided.
syntax
(define-ebb-transformer (id . formals) def ... #:receive el body ... maybe-finish)
maybe-finish = #:finish end ...
The transformer receives elements in the el binding and should process them in the body ... expressions. It can either pass the value as-is using (yield el), modify it and then pass it on, or - if it needs to skip a particular value - it just does not yield.
If the stream of values received by the transformer terminates and the transformer has provided some end ... expressions, they are evaluated and may handle certain cases specially.
Typical special case is invoking (finish/f) if no elements matched and given transformer is expected to return #f in case of no matches. When used with short-circuiting ebb/and, nothing happens and the whole fused stream returns #f. When used in standalone ebb, it will generate a runtime error in most cases as expected.
syntax
(define-ebb-consumer (id . formals) maybe-maybe/f def ... #:receive el body ... #:finish end ...)
maybe-maybe/f =
| #:maybe/f?
If #:maybe/f? is specified, than this consumer reacts gracefully to special case of stream termination. See define-ebb-transformer for details on finish/f.
Typically the consumer defines some state variables in the def ... expressions and updates them as it receives el elements in the body ... expressions. The end ... expressions are mandatory for consumers as they must explicitly return something. The result of the last end expression is the result of the fused stream.
Anytime the body may evaluate the (finish) to terminate the stream and give control to the end expressions. A special form (finish val) is provided to also return an explicit value.
syntax
(define-ebb-rule alias (orig arg ...)) (define-ebb-rule (alias aarg ...) (orig arg ...))