Skip to content

@epikodelabs/streamix


@epikodelabs/streamix / src/public-api / createOperator

Function: createOperator()

createOperator<T, R>(name, transformFn): Operator<T, R>

Defined in: projects/libraries/streamix/src/lib/atoms/operator.ts:107

Creates a reusable stream operator.

This factory function simplifies the creation of operators by bundling a name and a transformation function into a single Operator object.

The returned operator automatically fills in missing return() and throw() methods on the produced iterator so that downstream consumers can always clean up properly:

  • Default return(): Forwards to source.return() (if present) and returns the caller-supplied value or the source's return value. Errors from source.return() are logged as warnings rather than silently swallowed.
  • Default throw(): Forwards to source.throw() (if present). If the source handles the throw and returns a non-done result, that result is forwarded. Otherwise the source is cleaned up via source.return() and the original error is re-thrown.

Type Parameters

T

T = any

The type of the value the operator will consume.

R

R = T

The type of the value the operator will produce.

Parameters

name

string

The name of the operator, for identification and debugging.

transformFn

(this, source) => AsyncIterator<R>

The transformation function that defines the operator's logic. Receives the operator instance as this, allowing access to this.name etc.

Returns

Operator<T, R>

A new Operator object with the specified name and transformation function.

Released under the GNU AGPL v3 or later.