1.0.6 • Published 6 years ago

@kingjs/linq.to-dictionary v1.0.6

Weekly downloads
-
License
MIT
Repository
github
Last release
6 years ago

@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

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago