1.0.10 • Published 6 years ago

@kingjs/linq.distinct v1.0.10

Weekly downloads
-
License
MIT
Repository
github
Last release
6 years ago

@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

1.0.10

6 years ago

1.0.9

6 years ago

1.0.8

6 years ago

1.0.7

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago