@kingjs/linq.then-by

1.0.6 • Public • Published

@kingjs/linq.then-by

Generates a sequence of elements from a sorted sequence where elements previously considered equal are put in ascending order according to a key.

Usage

Sort Bob Smith, Alice Smith, and Chris King in ascending order by last name then first name like this:

var orderBy = require('@kingjs/linq.order-by');
var thenBy = require('@kingjs/linq.then-by');
var sequence = require('@kingjs/enumerable.create');
var toArray = require('@kingjs/linq.to-array');

var people = sequence(
  { first: 'Bob', last: 'Smith' },
  { first: 'Alice', last: 'Smith' },
  { first: 'Chris', last: 'King' },
);

var lastSelector = function(x) { return x.last; }
var firstSelector = function(x) { return x.first; }

var sortedSequence = orderBy.call(people, lastSelector);
sortedSequence = thenBy.call(sortedSequence, firstSelector);

toArray.call(sortedSequence);

result:

[
  { first: 'Chris', last: 'King' },
  { first: 'Alice', last: 'Smith' },
  { first: 'Bob', last: 'Smith' },
]

API

declare function thenBy(
  this: SortedEnumerable, 
  keySelector?: (x) => any,
  lessThan?: (l, r) => boolean,
): SortedEnumerable

Interfaces

Parameters

  • this: A sorted sequence of element to subsequently sort.
  • keySelector: Select a value by which to sort. By default, returns the element.
  • lessThan: Compare if one key is less than another. By default, uses the < operator.

Return Value

A refined sorted sequence in descending order.

See Also

Install

With npm installed, run

$ npm install @kingjs/link.then-by

Acknowledgments

Like Enumerable.ThenBy

License

MIT

Analytics

Readme

Keywords

none

Package Sidebar

Install

npm i @kingjs/linq.then-by

Weekly Downloads

0

Version

1.0.6

License

MIT

Unpacked Size

4.1 kB

Total Files

4

Last publish

Collaborators

  • kingces95