tyneq / createOperator
Function: createOperator()
createOperator<
TSource,TArgs,TResult>(config):void
Defined in: src/plugin/registration/createOperator.ts:48
Registers a streaming or buffering operator using a factory function.
Use this when the operator requires a class-level enumerator with custom state but you want to avoid writing the decorator boilerplate. For simpler generator-based operators, prefer createGeneratorOperator.
Type Parameters
| Type Parameter |
|---|
TSource |
TArgs extends unknown[] |
TResult |
Parameters
| Parameter | Type | Description |
|---|---|---|
config | { name: string; category: "streaming" | "buffer"; factory: (source, ...args) => EnumeratorFactory<TResult>; validate?: (...args) => void; source?: OperatorSource; } | - |
config.name | string | Method name to expose on every sequence. |
config.category | "streaming" | "buffer" | "streaming" or "buffer". |
config.factory | (source, ...args) => EnumeratorFactory<TResult> | Returns an EnumeratorFactory given the source and arguments. |
config.validate? | (...args) => void | Optional eager validation for user-supplied arguments. |
config.source? | OperatorSource | - |
Returns
void
Example
ts
import { createOperator } from "tyneq/plugin";
import type { Enumerator } from "tyneq";
createOperator({
name: "everyOther",
category: "streaming",
factory: <T>(source: Enumerable<T>) => ({
getEnumerator(): Enumerator<T> {
let skip = false;
const iter = source[Symbol.iterator]();
return {
next(): IteratorResult<T> {
while (true) {
const r = iter.next();
if (r.done) return r;
if (!skip) { skip = true; return r; }
skip = false;
}
}
};
}
})
});