diff --git a/src/types/augmentations.ts b/src/types/augmentations.ts index 17ee0c90..692aadd1 100644 --- a/src/types/augmentations.ts +++ b/src/types/augmentations.ts @@ -1,3 +1,34 @@ // tslint:disable:no-unused-variable -// currently there are no augmenatations +import { Enumerable, OrderedEnumerable, Comparer } from 'ix'; + +// we want to reuse the createOrderedEnumerable that comes with OrderedEnumerable +interface OrderedEnumerablePrototype extends OrderedEnumerable { + createOrderedEnumerable(keySelector: (item: T) => TKey, comparer: Comparer | undefined, descending: boolean): OrderedEnumerable; +} + +// reach in and grab the OrderedEnumerable prototype by creating an ordered enumerable +const orderedEnumerablePrototype: OrderedEnumerablePrototype = (Enumerable) + .empty() + .orderBy(undefined) + .__proto__ + .constructor + .prototype; + +function thenBy( + this: OrderedEnumerablePrototype, + keySelector: (item: T) => TKey, + comparer?: Comparer, +) { + return this.createOrderedEnumerable(keySelector, comparer, false); +} +orderedEnumerablePrototype.thenBy = thenBy; + +function thenByDescending( + this: OrderedEnumerablePrototype, + keySelector: (item: T) => TKey, + comparer?: Comparer, +) { + return this.createOrderedEnumerable(keySelector, comparer, true); +} +orderedEnumerablePrototype.thenByDescending = thenByDescending;