tyneq / cachedOperator
Function: cachedOperator()
cachedOperator<
TArgs>(name,category,validate?): <TClass>(target,_context) =>TClass
Defined in: src/plugin/decorators/cachedOperator.ts:41
Class decorator that registers a TyneqCachedEnumerator subclass as an operator available only on cached sequences.
The enumerator constructor receives the full TyneqCachedEnumerable as its first argument (not just an Enumerator<T>).
Type Parameters
| Type Parameter | Default type |
|---|---|
TArgs extends unknown[] | never |
Parameters
| Parameter | Type | Description |
|---|---|---|
name | string | Method name to expose on cached sequences. |
category | "streaming" | "buffer" | Operator kind ("streaming" |
validate? | (...args) => void | Optional eager validation function for user-supplied arguments. |
Returns
<
TClass>(target,_context):TClass
Type Parameters
| Type Parameter |
|---|
TClass extends Constructor<any> |
Parameters
| Parameter | Type |
|---|---|
target | TClass |
_context | ClassDecoratorContext<TClass> |
Returns
TClass
Example
ts
import { cachedOperator, TyneqCachedEnumerator } from "tyneq/plugin";
@cachedOperator("myRefresh", "buffer")
class MyRefreshEnumerator<T> extends TyneqCachedEnumerator<T> {
private readonly iter: Enumerator<T>;
public constructor(source: CachedEnumerable<T>) {
super(source);
this.iter = this.cachedSource.getEnumerator();
}
protected handleNext(): IteratorResult<T> {
// this.cachedSource gives access to the full CachedEnumerable
return this.iter.next();
}
}