-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Pat Sissons
committed
Aug 2, 2017
1 parent
0803cc3
commit ce13702
Showing
1 changed file
with
32 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<T> extends OrderedEnumerable<T> { | ||
createOrderedEnumerable<TKey>(keySelector: (item: T) => TKey, comparer: Comparer<TKey, TKey> | undefined, descending: boolean): OrderedEnumerable<T>; | ||
} | ||
|
||
// reach in and grab the OrderedEnumerable prototype by creating an ordered enumerable | ||
const orderedEnumerablePrototype: OrderedEnumerablePrototype<any> = (<any>Enumerable) | ||
.empty() | ||
.orderBy(undefined) | ||
.__proto__ | ||
.constructor | ||
.prototype; | ||
|
||
function thenBy<T, TKey>( | ||
this: OrderedEnumerablePrototype<T>, | ||
keySelector: (item: T) => TKey, | ||
comparer?: Comparer<TKey, TKey>, | ||
) { | ||
return this.createOrderedEnumerable(keySelector, comparer, false); | ||
} | ||
orderedEnumerablePrototype.thenBy = thenBy; | ||
|
||
function thenByDescending<T, TKey>( | ||
this: OrderedEnumerablePrototype<T>, | ||
keySelector: (item: T) => TKey, | ||
comparer?: Comparer<TKey, TKey>, | ||
) { | ||
return this.createOrderedEnumerable(keySelector, comparer, true); | ||
} | ||
orderedEnumerablePrototype.thenByDescending = thenByDescending; |