1.0.10 • Published 7 years ago
@kingjs/linq.distinct v1.0.10
@kingjs/linq.distinct
Generates a sequence composed of the distinct elements of another sequence.
Usage
Remove duplicates from the sequence 0, 0 like this:
var distinct = require('@kingjs/linq.distinct');
var sequence = require('@kingjs/enumerable.create');
var toArray = require('@kingjs/linq.to-array');
var justZero = distinct.call(sequence(0, 0));
toArray.call(justZero);result:
[0]Remove duplicates from a sequence based on an id like this:
var distinct = require('@kingjs/linq.distinct');
var sequence = require('@kingjs/enumerable.create');
var toArray = require('@kingjs/linq.to-array');
var enumerable = sequence(
{ id: 0, name: 'foo' },
{ id: 0, name: 'bar' }
);
var justZero = distinct.call(
enumerable,
function(x) { return x.id; }
);
toArray.call(justZero);result:
[{
id: 0,
name: 'foo'
}]API
function distinct(
this: Enumerable,
selectId?: (x) => any
): Enumerable;Interfaces
Enumerable: See @kingjs/enumerable.define.
Parameters
this: The sequence to deduplicate.selectId: Optional, function to select an identifier.
Result
Returns a de-duplicated sequence.
Install
With npm installed, run
$ npm install @kingjs/link.distinctAcknowledgments
Like Enumerable.Distinct.
License
MIT