@kingjs/linq.distinct

1.0.10 • Public • Published

@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

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.distinct

Acknowledgments

Like Enumerable.Distinct.

License

MIT

Analytics

Readme

Keywords

none

Package Sidebar

Install

npm i @kingjs/linq.distinct

Weekly Downloads

0

Version

1.0.10

License

MIT

Unpacked Size

3.51 kB

Total Files

4

Last publish

Collaborators

  • kingces95