@kingjs/linq.to-lookup

Creates a dictionary from a sequence where values are groups of elements keyed by a name common to all members of the group.

Stats

StarsIssuesVersionUpdatedCreatedSize
@kingjs/linq.to-lookup
1.0.83 years ago3 years agoMinified + gzip package size for @kingjs/linq.to-lookup in KB

Readme

@kingjs/linq.to-lookup

Creates a dictionary from a sequence where values are groups of elements keyed by a name common to all members of the group.

Usage

If the following people own the following pets

  • Alice owns Fluffy
  • Alice owns Spike
  • Bob owns Tiger

then create a lookup from

  • Alice to Fluffy and Spike
  • Bob to Tiger

like this:

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

var lookup = toLookup.call(
  sequence(
    { name: 'Alice', pet: 'Fluffy' },
    { name: 'Alice', pet: 'Spike' },
    { name: 'Bob', pet: 'Tiger' }
  ),
  function(x) { return x.name; },
  function(x) { return x.pet; }
)

for (var key in lookup)
  lookup[key] = toArray.call(lookup[key]);
  
lookup;

result:

{
  Alice: [ 'Fluffy', 'Spike' ],
  Bob: [ 'Tiger' ]
}

API

declare function(
  this: Enumerable,
  keySelector: function(x): any,
  valueSelector?: function(x): any,
): Dictionary

Interfaces

  • Enumerable: See @kingjs/enumerable.define.
  • Dictionary: See @kingjs/dictionary.

    Parameters

  • this: Sequence to partition into named sequences.
  • keySelector: Selects a partition key from an element.
  • valueSelector: Transforms an element before inclusion in a partition. By default, selects the entire element.

    Return Value

    A partitioning of the sequence as a dictionary mapping partition names to partitions.

    Install

    With npm installed, run
    $ npm install @kingjs/linq.to-lookup
    

    Acknowledgments

    Like Enumerable.ToLookup.

    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.