@kingjs/linq.union

1.0.10 • Public • Published

@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

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

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.0.10
    0
    • latest

Version History

Package Sidebar

Install

npm i @kingjs/linq.union

Weekly Downloads

0

Version

1.0.10

License

MIT

Unpacked Size

4.85 kB

Total Files

4

Last publish

Collaborators

  • kingces95