Skip to content

tyneq


tyneq / orderedOperator

Function: orderedOperator()

orderedOperator<TArgs>(name, category, validate?): <TClass>(target, _context) => TClass

Defined in: src/plugin/decorators/orderedOperator.ts:43

Class decorator that registers a TyneqOrderedEnumerator subclass as an operator available only on ordered sequences.

The enumerator constructor receives the full TyneqOrderedEnumerable 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 ordered 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 { orderedOperator, TyneqOrderedEnumerator } from "tyneq/plugin";

@orderedOperator("myThenBy", "buffer", (keySelector) => {
    if (typeof keySelector !== "function") throw new Error("keySelector must be a function");
})
class MyThenByEnumerator<T> extends TyneqOrderedEnumerator<T> {
    private readonly iter: Enumerator<T>;
    public constructor(source: OrderedEnumerable<T>, private readonly keySelector: (item: T) => unknown) {
        super(source);
        this.iter = this.orderedSource.getEnumerator();
    }
    protected handleNext(): IteratorResult<T> {
        // this.orderedSource gives access to the full OrderedEnumerable
        return this.iter.next();
    }
}