Skip to content
This repository has been archived by the owner on Apr 20, 2018. It is now read-only.

thenByDescending sorts ascending, thenBy ignores comparer #22

Open
patsissons opened this issue Aug 2, 2017 · 0 comments · May be fixed by #23
Open

thenByDescending sorts ascending, thenBy ignores comparer #22

patsissons opened this issue Aug 2, 2017 · 0 comments · May be fixed by #23

Comments

@patsissons
Copy link

https://github.com/Reactive-Extensions/IxJS/blob/master/src/core/enumerable.js#L1615
https://github.com/Reactive-Extensions/IxJS/blob/master/src/core/enumerable.js#L1611

for those that run into this, here is an augmentation to patch the issue until it's fixed. I'll try and get a PR for this issue pushed up asap.

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;
patsissons pushed a commit to marinels/webrx-react that referenced this issue Aug 2, 2017
@patsissons patsissons linked a pull request Aug 2, 2017 that will close this issue
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant