On this page:
define-ebb-producer
define-ebb-transformer
define-ebb-consumer
define-ebb-rule
9.1

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-producer (id . formals) body ...)

Defines a new ebb stream producer and binds it to given id. The arguments can be specified as with any Racket procedure formal arguments including keyword arguments. The body of the producer should use (yield val) to provide values downstream.

syntax

(define-ebb-transformer (id . formals)
  def ...
  #:receive el
  body ...
  maybe-finish)
 
maybe-finish = #:finish end ...
Defines a new stream transformer. Any definitions in def ... are persistent for the whole lifetime of given stream evaluation.

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?
Defines a new stream consumer following a similar pattern as define-ebb-producer and define-ebb-transformer.

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)

(define-ebb-rule alias (orig arg ...))
(define-ebb-rule (alias aarg ...) (orig arg ...))
Defines an alias for orig ebb step as a simple syntax rule.