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

thenByDescending sorts ascending, thenBy ignores comparer #22

@patsissons

Description

@patsissons

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;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions