Skip to content

tyneq


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 ParameterDefault type
TArgs extends unknown[]never

Parameters

ParameterTypeDescription
namestringMethod name to expose on cached sequences.
category"streaming" | "buffer"Operator kind ("streaming"
validate?(...args) => voidOptional eager validation function for user-supplied arguments.

Returns

<TClass>(target, _context): TClass

Type Parameters

Type Parameter
TClass extends Constructor<any>

Parameters

ParameterType
targetTClass
_contextClassDecoratorContext<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();
    }
}