@kingjs/linq.except

1.0.12 • Public • Published

@kingjs/linq.except

Generates the set difference of two sequences.

Usage

Remove duplicates from the sequence 0, 0, 1, 2 and also exclude values 1 and 2 like this:

var except = require('@kingjs/linq.except');
var sequence = require('@kingjs/enumerable.create');
var toArray = require('@kingjs/linq.to-array');

var justZero = except.call(
  sequence(0, 0, 1, 2),
  sequence(1, 2)
);

toArray.call(justZero);

result:

[0]

Remove duplicates from a sequence based on an id and also exclude those with id equal to 1 like this:

var except = require('@kingjs/linq.except');
var sequence = require('@kingjs/enumerable.create');
var toArray = require('@kingjs/linq.to-array');

var enumerable = sequence(
  { id: 0, name: 'foo' },
  { id: 0, name: 'bar' },
  { id: 1, name: 'baz' }
);

var justZero = except.call(
  enumerable,
  sequence({ id: 1, name: 'moo' }),
  function(x) { return x.id; }
);

toArray.call(justZero);

result:

[{ 
  id: 0,
  name: 'foo'
}]

API

function except(
  this: Enumerable, 
  exceptions: Enumerable, 
  idSelector?: (x) => any
): Enumerable;

Interfaces

Parameters

  • this: The first sequence.
  • exceptions: The second sequence.
  • idSelector: Return a value whose stringified representation uniquely identifies an element.
    • x: The element to identify.

Result

Returns elements in the first sequence except those also present in the second sequence.

Remarks

Elements are deemed equal if their stringified id representations returned by idSelector are the same.

Only unique elements are included in the resulting sequence.

Elements are included in the order they appear in the first sequence.

Install

With npm installed, run

$ npm install @kingjs/link.exclude

Acknowledgments

Like Enumerable.Exclude.

License

MIT

Analytics

Readme

Keywords

none

Package Sidebar

Install

npm i @kingjs/linq.except

Weekly Downloads

0

Version

1.0.12

License

MIT

Unpacked Size

4.96 kB

Total Files

4

Last publish

Collaborators

  • kingces95