1.0.30 • Published 6 years ago

@kingjs/linq v1.0.30

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

@kingjs/linq

Exports all @kingjs/linq.* functionality in one package.

Usage

Join pets to their owners, sorted by last name, then first name, excluding fishes, like this:

var linq = require('@kingjs/linq');
var sequence = require('@kingjs/enumerable.create');
var apply = require('@kingjs/apply');

var people = sequence(
  { firstName: 'Bob', lastName: 'Smith', id: 0 },
  { firstName: 'Alice', lastName: 'Smith', id: 1 },
  { firstName: 'Chris', lastName: 'King', id: 2 },
);

var pets = sequence(
  { name: 'Tiger', type: 'dog', ownerId: 0 },
  { name: 'Spike', type: 'dog', ownerId: 0 },
  { name: 'Fluffy', type: 'cat', ownerId: 1 },
  { name: 'Bubbles', type: 'fish', ownerId: 2 },
);

apply.call(people,
  linq.orderBy, [ function(x) { return x.lastName; } ],
  linq.thenBy, [ function(x) { return x.firstName; } ],
  linq.join, [
    pets, 
    function(x) { return x.id; },
    function(x) { return x.ownerId; },
    function(owner, pet) { return { owner: owner, pet: pet } }
  ],
  linq.where, [ function(x) { return x.pet.type != 'fish'; } ],
  linq.select, [
    function(x) { 
      var owner = x.owner;
      var pet = x.pet;

      return owner.firstName + " " + owner.lastName + 
        ' owns a ' + pet.type + ' named ' + pet.name + '.';
    },
  ],
  linq.toArray, [],
  Array.prototype.join, ['\n']
);

result:

Alice Smith owns a cat named Fluffy. 
Bob Smith owns a dog named Tiger. 
Bob Smith owns a dog named Spike.

API

SearchAggregateSetGeneratorAccrete
allaggregatedistinctrangeappend
anyaverageexceptrepeatconcat
containscountintersectemptyprepend
elementAtOrUndefmaxunion
firstOrUndefmin
lastOrUndefsum
singleOrUndefequal
SortFilterJoinTransformContainer
orderByskipgroupByselecttoArray
orderByDescskipWhilegroupJoinselectManytoDictionary
thenBytakejointoLookup
thenByDesctakeWhilezip
where

Install

With npm installed, run

$ npm install @kingjs/link

Remarks

See @kingjs/apply to understand the benefit of the "odd" apply convention. Basically, it allows for the separation of data from algorithm; Data and algorithm separation cannot be achieved in Javascript using the dot syntax without polluting the data object or prototype with a function.

See Also

Acknowledgments

Like LINQ.

License

MIT

Analytics

1.0.30

6 years ago

1.0.29

6 years ago

1.0.28

6 years ago

1.0.27

6 years ago

1.0.26

6 years ago

1.0.25

6 years ago

1.0.24

6 years ago

1.0.23

6 years ago

1.0.22

6 years ago

1.0.21

6 years ago

1.0.20

6 years ago

1.0.19

6 years ago

1.0.18

6 years ago

1.0.17

6 years ago

1.0.16

6 years ago

1.0.15

6 years ago

1.0.14

6 years ago

1.0.13

6 years ago

1.0.12

6 years ago

1.0.11

6 years ago

1.0.10

6 years ago

1.0.9

6 years ago

1.0.8

6 years ago

1.0.7

6 years ago

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