@kingjs/linq.distinct

Generates a sequence composed of the distinct elements of another sequence.

Stats

StarsIssuesVersionUpdatedCreatedSize
@kingjs/linq.distinct
1.0.103 years ago3 years agoMinified + gzip package size for @kingjs/linq.distinct in KB

Readme

@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

If you find any bugs or have a feature request, please open an issue on github!

The npm package download data comes from npm's download counts api and package details come from npms.io.