@kingjs/linq.union

Generates the set union of two sequences.

Stats

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

Readme

@kingjs/linq.union

Generates the set union of two sequences.

Usage

Create a union of the sequences

  • 0, 0, 1, 2, and
  • 1, 3, 3

like this:

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

var result = union.call(
  sequence(0, 0, 1, 2),
  sequence(1, 3, 3)
);

toArray.call(result);

result:

[0, 1, 2, 3]

Create a union of the same sequences as before but wrapped in an object like this:

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

var result = union.call(
  sequence({ id: 0 }, { id: 0 }, { id: 1 }, { id: 2 }),
  sequence({ id: 1 }, { id: 3 }, { id: 3 }),
  function(x) { return x.id; }
);

toArray.call(result);

result:

[{ id: 0 }, { id: 1 }, { id: 2 }, { id: 3 }]

API

function union(
  this: Enumerable, 
  second: Enumerable, 
  idSelector?: (x) => any
): Enumerable;

Interfaces

  • Enumerable: See @kingjs/enumerable.define.

    Parameters

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

      Result

      A sequence containing unique elements of sequences first and second.

      Remarks

      Elements are deemed equal if their key's stringified representations are the same.

Elements are included in the order they are appear in the first sequence and then the second sequence.

Install

With npm installed, run

$ npm install @kingjs/link.union

Acknowledgments

Like Enumerable.Union.

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.