@kingjs/linq.join

1.0.5 • Public • Published

@kingjs/linq.join

Generates a sequence of elements composed of elements from two sequences that share a common key.

Usage

Match people Alice, Bob, and Chris to their pets Fluffy, Spike, Snuggles, and Butch like this:

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

var result = join.call(
  sequence(
    { name: `Alice`, key: 0 },
    { name: `Bob`, key: 1 },
    { name: `Chris`, key: 2 }, // no pets
  ), 
  sequence(
    { name: `Fluffy`, ownerKey: 0 },
    { name: `Spike`, ownerKey: 0 },
    { name: `Snuggles`, ownerKey: 1 },
    { name: `Butch`, ownerKey: 3 }, // no owner
  ),
  function(person) { return person.key; },
  function(animal) { return animal.ownerKey; },
  function(owner, pet) { return owner.name + ' owns ' + pet.name; },
)

toArray.call(result);

result:

[ 
  'Alice owns Fluffy',
  'Alice owns Spike',
  'Bob owns Snuggles',
]

API

declare function join(
  this: Enumerable,
  outer: Enumerable,
  innerKeySelector: (innerElement) => any,
  outerKeySelector: (outerElement) => any,
  resultSelector: (innerElement, outerElement) => any
): any

Interfaces

Parameters

  • this: The outer sequence.
  • inner: The inner sequence.
  • outerKeySelector: Selects a key from elements of the outer sequence.
  • innerKeySelector: Selects a key from elements of the inner sequence.
  • resultSelector: Composes a result element from an inner and an outer element which share a common key.
    • innerElement: The inner element.
    • outerElement: The outer element.

Return Value

A sequence of elements composed of elements from two sequences that share a common key.

Remarks

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

Matching elements are generated in the order their inner element, then outer element, occur in their respective sequences.

Install

With npm installed, run

$ npm install @kingjs/linq.join

Acknowledgments

Like Enumerable.Join.

License

MIT

Analytics

Dependencies (2)

Dev Dependencies (0)

    Package Sidebar

    Install

    npm i @kingjs/linq.join

    Weekly Downloads

    0

    Version

    1.0.5

    License

    MIT

    Unpacked Size

    5.61 kB

    Total Files

    4

    Last publish

    Collaborators

    • kingces95