@kingjs/linq.to-dictionary

1.0.6 • Public • Published

@kingjs/linq.to-dictionary

Creates a dictionary from a sequence where the dictionary keys and values are projected from each element.

Usage

Create a dictionary of people's ages by their name like this:

var sequence = require('@kingjs/enumerable.create');
var toDictionary = require('@kingjs/linq.to-dictionary');

toDictionary.call(
  sequence(
    { name: 'Alice', age: 18 },
    { name: 'Bob', age: 19 },
    { name: 'Chris', age: 20 },
  ), 
  function(x) { return x.name; },
  function(x) { return x.age; }
);

result:

{
  Alice: 18,
  Bob: 19,
  Chris: 20
}

API

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

Interfaces

Parameters

  • this: Sequence to turn into a dictionary.
  • selectKey: Select a key for each element.
  • selectValue: Select a value for each element.

Return Value

Returns a dictionary of one key/value pair for each element. Throws if more than one element maps to the same key.

Install

With npm installed, run

$ npm install @kingjs/linq.to-dictionary

Acknowledgments

Like: Enumerable.Dictionary

License

MIT

Analytics

/@kingjs/linq.to-dictionary/

    Package Sidebar

    Install

    npm i @kingjs/linq.to-dictionary

    Weekly Downloads

    5

    Version

    1.0.6

    License

    MIT

    Unpacked Size

    3.88 kB

    Total Files

    4

    Last publish

    Collaborators

    • kingces95