open-index/open-npm huggingface dataset:
npm package: @kingjs/linq.element-at-or-default
Description: Return the element at a specified index in a sequence.
Author: Chris King
Latest version: 1.0.0
Deprecated: see @kingjs/linq.element-ar-or-undefined

# @[kingjs](https://www.npmjs.com/package/kingjs)/[linq](https://www.npmjs.com/package/@kingjs/linq).element-at-or-default
Return the element at a specified index in a sequence.

## Usage
Return the 2nd element in the sequence `0`, `1`, `2` like this:
```js
var elementAt = require('@kingjs/linq.element-at');
var sequence = require('@kingjs/sequence');

elementAt.call(sequence(0, 1, 2), 1);
```
result:
```js
1
```

## API
```ts
declare function elementAt(
  this: Enumerable,
  index: number
): any
```
### Interfaces
- `Enumerable`: See [@kingjs/sequence](https://www.npmjs.com/package/@kingjs/sequence).

### Parameters
- `this`: The sequence to traverse.
- `index`: The 0 based index of of the sequence to return.

### Return Value
The 0 based index of of the sequence or undefined.

## Install
With [npm](https://npmjs.org/) installed, run

```
$ npm install @kingjs/linq.element-at-or-default
```
## See Also
Like [Enumerable.ElementAt](https://msdn.microsoft.com/en-us/library/bb494386(v=vs.110).aspx).

## License

MIT
npm package: @kingjs/linq.element-at-or-undefined
Description: Returns the element at a specified index in a sequence or undefined if the index is out of range.
Author: Chris King
Latest version: 1.0.6

# @[kingjs](https://www.npmjs.com/package/kingjs)/[linq](https://www.npmjs.com/package/@kingjs/linq).element-at-or-default
Returns the element at a specified index in a sequence or undefined if the index is out of range.
## Usage
Return the 2nd element in the sequence `0`, `1`, `2` like this:
```js
var elementAt = require('@kingjs/linq.element-at-or-undefined');
var sequence = require('@kingjs/enumerable.create');

elementAt.call(sequence(0, 1, 2), 1);
```
result:
```js
1
```

## API
```ts
declare function elementAt(
  this: Enumerable,
  index: number
): any
```
### Interfaces
- `Enumerable`: See [@kingjs/enumerable.define](https://www.npmjs.com/package/@kingjs/enumerable.define).

### Parameters
- `this`: The sequence to traverse.
- `index`: The 0 based index of of the sequence to return.

### Return Value
The 0 based index of of the sequence or undefined.

## Install
With [npm](https://npmjs.org/) installed, run

```
$ npm install @kingjs/linq.element-at-or-default
```
## See Also
Like [Enumerable.ElementAt](https://msdn.microsoft.com/en-us/library/bb494386(v=vs.110).aspx).

## License

MIT

![Analytics](https://analytics.kingjs.net/linq/element-at-or-undefined)
npm package: @kingjs/linq.empty
Description: Returns an empty sequence.
Author: Chris King
Latest version: 1.0.7

# @[kingjs](https://www.npmjs.com/package/kingjs)/[linq](https://www.npmjs.com/package/@kingjs/linq).empty
Returns an empty sequence.
## Usage
Generate an empty sequence like this:
```js
var empty = require('@kingjs/linq.empty');
var toArray = require('@kingjs/linq.to-array');

toArray.call(empty());
```
result:
```js
[]
```
## API
```ts
declare function(): Enumerable;
```
### Interfaces
- `Enumerable`: See [@kingjs/enumerable.define](https://www.npmjs.com/package/@kingjs/enumerable.define).
### Result
An empty sequence.
## Install
With [npm](https://npmjs.org/) installed, run
```
$ npm install @kingjs/link.empty
```
## Acknowledgments
Like [`Enumerable.Empty`](https://msdn.microsoft.com/en-us/library/bb341042(v=vs.110).aspx).
## License
MIT

![Analytics](https://analytics.kingjs.net/linq/empty)
npm package: @kingjs/linq.except
Description: Generates the set difference of two sequences.
Author: Chris King
Latest version: 1.0.12

# @[kingjs](https://www.npmjs.com/package/kingjs)/[linq](https://www.npmjs.com/package/@kingjs/linq).except
Generates the set difference of two sequences.
## Usage
Remove duplicates from the sequence `0`, `0`, `1`, `2` and also exclude values `1` and `2` like this:
```js
var except = require('@kingjs/linq.except');
var sequence = require('@kingjs/enumerable.create');
var toArray = require('@kingjs/linq.to-array');

var justZero = except.call(
  sequence(0, 0, 1, 2),
  sequence(1, 2)
);

toArray.call(justZero);
```
result:
```js
[0]
```
Remove duplicates from a sequence based on an `id` and also exclude those with `id` equal to `1` like this:
```js
var except = require('@kingjs/linq.except');
var sequence = require('@kingjs/enumerable.create');
var toArray = require('@kingjs/linq.to-array');

var enumerable = sequence(
  { id: 0, name: 'foo' },
  { id: 0, name: 'bar' },
  { id: 1, name: 'baz' }
);

var justZero = except.call(
  enumerable,
  sequence({ id: 1, name: 'moo' }),
  function(x) { return x.id; }
);

toArray.call(justZero);
```
result:
```js
[{ 
  id: 0,
  name: 'foo'
}]
```

## API
```ts
function except(
  this: Enumerable, 
  exceptions: Enumerable, 
  idSelector?: (x) => any
): Enumerable;
```
### Interfaces
- `Enumerable`: See [@kingjs/enumerable.define](https://www.npmjs.com/package/@kingjs/enumerable.define).

### Parameters
- `this`: The first sequence.
- `exceptions`: The second sequence.
- `idSelector`: Return a value whose stringified representation uniquely identifies an element.
  - `x`: The element to identify.

### Result
Returns elements in the first sequence except those also present in the second sequence.
## Remarks
Elements are deemed equal if their stringified id representations returned by `idSelector` are the same.

Only unique elements are included in the resulting sequence. 

Elements are included in the order they appear in the first sequence.
## Install
With [npm](https://npmjs.org/) installed, run

```
$ npm install @kingjs/link.exclude
```

## Acknowledgments
Like [`Enumerable.Exclude`](https://msdn.microsoft.com/en-us/library/bb336390(v=vs.110).aspx).

## License

MIT

![Analytics](https://analytics.kingjs.net/linq/except)
npm package: @kingjs/linq.first
Description: Returns the first element of a sequence that satisfies a specified condition.
Author: Chris King
Latest version: 1.0.7

# @[kingjs](https://www.npmjs.com/package/kingjs)/[linq](https://www.npmjs.com/package/@kingjs/linq).first
Returns the first element of a sequence that satisfies a specified condition.
## Usage
Return the first value of `0`, `1`, `2` like this;
```js
var firstOrUndefined = require('@kingjs/linq.first');
var sequence = require('@kingjs/enumerable.create');

firstOrUndefined.call(sequence(0, 1, 2));
```
result:
```js
0
```
Return the first odd value of `0`, `1`, `2` like this;
```js
var firstOrUndefined = require('@kingjs/linq.first');
var sequence = require('@kingjs/enumerable.create');

var isOdd = function(x) { return x % 2 == 1; }

firstOrUndefined.call(sequence(0, 1, 2), isOdd);
```
result:
```js
1
```

## API
```ts
declare function first(
  this: Enumerable,
  predicate?: (x) => boolean
)
```

### Interfaces
- `Enumerable`: See [@kingjs/enumerable.define](https://www.npmjs.com/package/@kingjs/enumerable.define).

### Parameters
- `this`: The sequence of which first element is returned.
- `predicate`: Optional predicate element must satisfy. 

### Return Value
First element in the sequence or throw if sequence is empty. If a predicate is provided, then the first element to match the predicate else throw if no element satisfies the predicate.

## Install
With [npm](https://npmjs.org/) installed, run

```
$ npm install @kingjs/linq.first
```

## Acknowledgments
Like [`Enumerable.First`](https://msdn.microsoft.com/en-us/library/bb535050(v=vs.110).aspx).

## License

MIT

![Analytics](https://analytics.kingjs.net/linq/first)
npm package: @kingjs/linq.first-or-undefined
Description: Returns the first element of a sequence that satisfies a specified condition or a undefined.
Author: Chris King
Latest version: 1.0.6

# @[kingjs](https://www.npmjs.com/package/kingjs)/[linq](https://www.npmjs.com/package/@kingjs/linq).first-or-undefined
Returns the first element of a sequence that satisfies a specified condition or a undefined.
## Usage
Return the first value of `0`, `1`, `2` like this;
```js
var firstOrUndefined = require('@kingjs/linq.first-or-undefined');
var sequence = require('@kingjs/enumerable.create');

firstOrUndefined.call(sequence(0, 1, 2));
```
result:
```js
0
```
Return the first odd value of `0`, `1`, `2` like this;
```js
var firstOrUndefined = require('@kingjs/linq.first-or-undefined');
var sequence = require('@kingjs/enumerable.create');

var isOdd = function(x) { return x % 2 == 1; }

firstOrUndefined.call(sequence(0, 1, 2), isOdd);
```
result:
```js
1
```

## API
```ts
declare function firstOrUndefined(
  this: Enumerable,
  predicate?: (x) => boolean
)
```

### Interfaces
- `Enumerable`: See [@kingjs/enumerable.define](https://www.npmjs.com/package/@kingjs/enumerable.define).

### Parameters
- `this`: The sequence of which first element is returned.
- `predicate`: Optional predicate element must satisfy. 

### Return Value
First element in the sequence or undefined if sequence is empty. If a predicate is provided, then the first element to match the predicate else undefined if no element satisfies the predicate.

## Install
With [npm](https://npmjs.org/) installed, run

```
$ npm install @kingjs/linq.first-or-undefined
```

## Acknowledgments
Like [`Enumerable.FirstOrDefault`](https://msdn.microsoft.com/en-us/library/bb549039(v=vs.110).aspx).

## License

MIT

![Analytics](https://analytics.kingjs.net/linq/first-or-undefined)
npm package: @kingjs/linq.group-by
Description: Generates a sequence of groups composed of elements of another sequence which share a common key.
Author: Chris King
Latest version: 1.0.11

# @[kingjs](https://www.npmjs.com/package/kingjs)/[linq](https://www.npmjs.com/package/@kingjs/linq).group-by
Generates a sequence of groups composed of elements of another sequence which share a common key.
## Usage
Group `0`, `1`, `2`, `3` by even/odd numbers like this:
```js
var groupBy = require('@kingjs/linq.group-by');
var sequence = require('@kingjs/enumerable.create');
var toArray = require('@kingjs/linq.to-array');

var evenOdd = groupBy.call(
  sequence(0, 1, 2, 3), 
  function(x) { return x % 2; }
);

var groups = toArray.call(evenOdd);
var even = groups[0];
var odd = groups[1];

var result = {
  evenKey: even.key,
  even: toArray.call(even),
  oddKey: odd.key,
  odd: toArray.call(odd),
};

result;
```
result:
```js
{
  evenKey: 0,
  even: [ 0, 2 ],
  oddKey: 0,
  odd: [ 1, 3 ],
}
```
Group people by their age and project their names like this:
```js
var groupBy = require('@kingjs/linq.group-by');
var sequence = require('@kingjs/enumerable.create');
var toArray = require('@kingjs/linq.to-array');

var people = groupBy.call(
  sequence(
    { name: 'Alice', age: 17 },
    { name: 'Bob', age: 16 },
    { name: 'Chris', age: 30 }
  ), 
  function(x) { return x.age <= 18; }, // key selector
  function(x) { return x.name; }, // element selector
  function(group) {  // result selector
    return 'Under 18: ' + group.key + '; ' + toArray.call(group).join(', ');
  },
);

toArray.call(people);
```
result:
```js
[
  'Under 18: true; Alice, Bob',
  'Under 18: false; Chris'
]
```

## API
```ts
declare function groupBy(
  this: Enumerable,
  keySelector: (x) => any,
  elementSelector?: (x) => any,
  resultSelector?: (group) => any
)
```

### Interfaces
- `Enumerable`: See [@kingjs/enumerable.define](https://www.npmjs.com/package/@kingjs/enumerable.define).

### Parameters
- `this`: The sequence to partition.
- `keySelector`: Selects key common to each group. 
- `elementSelector`: Maps an element before inclusion in a group. 
- `resultSelector`: Maps a group before returned.
  - `group`: Sequence of elements in the group.  

### Return Value
Sequence of sub-sequences where each sub-sequence contains elements forming a group. Each group has a `key` property whose value was selected by `keySelector` and is shared by elements of the group.

## Install
With [npm](https://npmjs.org/) installed, run

```
$ npm install @kingjs/linq.group-by
```

## Acknowledgments
Like [`Enumerable.GroupBy`](https://msdn.microsoft.com/en-us/library/bb535049(v=vs.110).aspx).

## License

MIT

![Analytics](https://analytics.kingjs.net/linq/group-by)
npm package: @kingjs/linq.group-join
Description: Generates a sequence of elements composed of an element in one sequence and a group of elements in another sequence all of which share a common key.
Author: Chris King
Latest version: 1.0.7

# @[kingjs](https://www.npmjs.com/package/kingjs)/[linq](https://www.npmjs.com/package/@kingjs/linq).group-join
Generates a sequence of elements composed of an element in one sequence and a group of elements in another sequence all of which share a common key.
## Usage
Join

- `Alice` with her pets `Fluffy` and `Spike`,
- `Bob` with his pet `Snuggles`, and
- `Chris` without any pets

like this:
```js
var groupJoin = require('@kingjs/linq.group-join');
var sequence = require('@kingjs/enumerable.create');
var toArray = require('@kingjs/linq.to-array');

var owners = sequence(
  { name: 'Alice', id: 0 },
  { name: 'Bob', id: 1 },
  { name: 'Chris', id: 2 },
);

var pets = sequence(
  { name: 'Fluffy', ownerId: 0 },
  { name: 'Spike', ownerId: 0 },
  { name: 'Snuggles', ownerId: 1 },
)

var ownersAndPets = groupJoin.call(
  owners,
  pets,
  function(x) { return x.id; },
  function(x) { return x.ownerId; },
  function(x, group) { 
    return {
      owner: x.name,
      pets: toArray.call(group)
    }; 
  }
);

toArray.call(ownersAndPets);
```
result:
```js
[{
  owner: 'Alice', 
  pets: [
    { name: 'Fluffy', ownerId: 0 },
    { name: 'Spike', ownerId: 0 },
  ],
}, {
  owner: 'Bob', 
  pets: [
    { name: 'Snuggles', ownerId: 1 },
  ],
}, {
  owner: 'Chris', 
  pets: [     
  ],
}]
```
## API
```ts
declare function groupJoin(
  this: Enumerable,
  outerEnumerable: Enumerable,
  innerKeySelector: (x) => any,
  outerKeySelector: (x) => any,
  resultSelector: (innerElement, outerPartition) => any
)
```
### Interfaces
- `Enumerable`: See [@kingjs/enumerable.define](https://www.npmjs.com/package/@kingjs/enumerable.define).
### Parameters
- `this`: The inner sequence whose elements are matched with a partition of the outer sequence.
- `outerEnumerable`: The outer sequence whose partitions are joined with elements of the inner sequence. 
- `innerKeySelector`: Selects a key from elements of the inner sequence.
- `outerKeySelector`: Selects a key from an element of the outer sequence which specifies the named partition to which the element belongs. 
- `resultSelector`: Joins inner elements to an outer partition which shares the same key.
  - `innerElement`: An inner element.
  - `outerPartition`: The outer partition that shares the same key as the inner element. 
### Return Value
A sequence of inner elements joined to partitions of outer elements.
## Install
With [npm](https://npmjs.org/) installed, run
```
$ npm install @kingjs/linq.group-join
```
## Acknowledgments
Like [`Enumerable.GroupJoin`](https://msdn.microsoft.com/en-us/library/bb534297(v=vs.110).aspx).
## License
MIT

![Analytics](https://analytics.kingjs.net/linq/group-join)
npm package: @kingjs/linq.intersect
Description: Generates the set intersection of two sequences.
Author: Chris King
Latest version: 1.0.8

# @[kingjs](https://www.npmjs.com/package/kingjs)/[linq](https://www.npmjs.com/package/@kingjs/linq).intersect
Generates the set intersection of two sequences.
## Usage
Intersect the numbers `0`, `0`, `1`, `2` with the numbers `1`, `0` like this:
```js
var intersect = require('@kingjs/linq.intersect');
var sequence = require('@kingjs/enumerable.create');
var toArray = require('@kingjs/linq.to-array');

var result = intersect.call(
  sequence(0, 0, 1, 2),
  sequence(1, 0)
)

toArray.call(result);
```
result:
```js
[ 0, 1 ]
```
## API
```ts
declare function intersect(
  this: Enumerable,
  second: Enumerable,
  idSelector?: (x) => any
)
```
### Interfaces
- `Enumerable`: See [@kingjs/enumerable.define](https://www.npmjs.com/package/@kingjs/enumerable.define).
### Parameters
- `this`: The first sequence.
- `second`: The second sequence. 
- `idSelector`: Return a value whose stringified representation uniquely identifies an element.
  - `x`: The element to identify.
### Return Value
A sequence of elements common to both sequences.
## Remarks
Elements are deemed equal if their stringified id representations returned by `idSelector` are the same.

Only unique elements are included in the resulting sequence. 

Elements are included in the order they appear in the first sequence.
## Install
With [npm](https://npmjs.org/) installed, run
```
$ npm install @kingjs/linq.intersect
```
## Acknowledgments
Like [`Enumerable.Intersect`](https://msdn.microsoft.com/en-us/library/bb355408(v=vs.110).aspx).
## License
MIT

![Analytics](https://analytics.kingjs.net/linq/intersect)
npm package: @kingjs/linq.join
Description: Generates a sequence of elements composed of elements from two sequences that share a common key.
Author: Chris King
Latest version: 1.0.5

# @[kingjs](https://www.npmjs.com/package/kingjs)/[linq](https://www.npmjs.com/package/@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:
```js
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:
```js
[ 
  'Alice owns Fluffy',
  'Alice owns Spike',
  'Bob owns Snuggles',
]
```
## API
```ts
declare function join(
  this: Enumerable,
  outer: Enumerable,
  innerKeySelector: (innerElement) => any,
  outerKeySelector: (outerElement) => any,
  resultSelector: (innerElement, outerElement) => any
): any
```
### Interfaces
- `Enumerable`: See [@kingjs/enumerable.define](https://www.npmjs.com/package/@kingjs/enumerable.define).
### 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](https://npmjs.org/) installed, run
```
$ npm install @kingjs/linq.join
```
## Acknowledgments
Like [`Enumerable.Join`](https://msdn.microsoft.com/en-us/library/bb534297(v=vs.110).aspx).
## License
MIT

![Analytics](https://analytics.kingjs.net/linq/join)
npm package: @kingjs/linq.last
Description: Returns the last element of a sequence that satisfies a specified condition.
Author: Chris King
Latest version: 1.0.7

# @[kingjs](https://www.npmjs.com/package/kingjs)/[linq](https://www.npmjs.com/package/@kingjs/linq).last
Returns the last element of a sequence that satisfies a specified condition.
## Usage
Return the last value of `0`, `1`, `2` like this;
```js
var lastOrUndefined = require('@kingjs/linq.last');
var sequence = require('@kingjs/enumerable.create');

lastOrUndefined.call(sequence(0, 1, 2));
```
result:
```js
2
```
Return the last odd value of `0`, `1`, `2`, `3`, `4` like this;
```js
var lastOrUndefined = require('@kingjs/linq.last');
var sequence = require('@kingjs/enumerable.create');

var isOdd = function(x) { return x % 2 == 1; }

lastOrUndefined.call(sequence(0, 1, 2, 3, 4), isOdd);
```
result:
```js
3
```

## API
```ts
declare function last(
  this: Enumerable,
  predicate?: (x) => boolean
)
```

### Interfaces
- `Enumerable`: See [@kingjs/enumerable.define](https://www.npmjs.com/package/@kingjs/enumerable.define).

### Parameters
- `this`: The sequence of which last element is returned.
- `predicate`: Optional predicate element must satisfy. 

### Return Value
Last element in the sequence or throw if sequence is empty. If a predicate is provided, then the last element to match the predicate else throw if no element satisfies the predicate.

## Install
With [npm](https://npmjs.org/) installed, run

```
$ npm install @kingjs/linq.last
```

## Acknowledgments
Like [`Enumerable.Last`](https://msdn.microsoft.com/en-us/library/bb549138(v=vs.110).aspx).

## License

MIT

![Analytics](https://analytics.kingjs.net/linq/last)
npm package: @kingjs/linq.last-or-undefined
Description: Returns the last element of a sequence that satisfies a specified condition or a undefined.
Author: Chris King
Latest version: 1.0.8

# @[kingjs](https://www.npmjs.com/package/kingjs)/[linq](https://www.npmjs.com/package/@kingjs/linq).last-or-undefined
Returns the last element of a sequence that satisfies a specified condition or a undefined.
## Usage
Return the last value of `0`, `1`, `2` like this;
```js
var lastOrUndefined = require('@kingjs/linq.last-or-undefined');
var sequence = require('@kingjs/enumerable.create');

lastOrUndefined.call(sequence(0, 1, 2));
```
result:
```js
2
```
Return the last odd value of `0`, `1`, `2`, `3`, `4` like this;
```js
var lastOrUndefined = require('@kingjs/linq.last-or-undefined');
var sequence = require('@kingjs/enumerable.create');

var isOdd = function(x) { return x % 2 == 1; }

lastOrUndefined.call(sequence(0, 1, 2, 3, 4), isOdd);
```
result:
```js
3
```

## API
```ts
declare function lastOrUndefined(
  this: Enumerable,
  predicate?: (x) => boolean
)
```

### Interfaces
- `Enumerable`: See [@kingjs/enumerable.define](https://www.npmjs.com/package/@kingjs/enumerable.define).

### Parameters
- `this`: The sequence of which last element is returned.
- `predicate`: Optional predicate element must satisfy. 

### Return Value
Last element in the sequence or undefined if sequence is empty. If a predicate is provided, then the last element to match the predicate else undefined if no element satisfies the predicate.

## Install
With [npm](https://npmjs.org/) installed, run

```
$ npm install @kingjs/linq.last-or-undefined
```

## Acknowledgments
Like [`Enumerable.LastOrDefault`](https://msdn.microsoft.com/en-us/library/bb548915(v=vs.110).aspx).

## License

MIT

![Analytics](https://analytics.kingjs.net/linq/last-or-undefined)
npm package: @kingjs/linq.max
Description: Returns the maximum value in a sequence of values projected from elements of a sequence.
Author: Chris King
Latest version: 1.0.6

# @[kingjs](https://www.npmjs.com/package/kingjs)/[linq](https://www.npmjs.com/package/@kingjs/linq).max
Returns the maximum value in a sequence of values projected from elements of a sequence.

## Usage
Return the maximum value of `1`, `2`, `3` like this:
```js
var max = require('@kingjs/linq.max');
var sequence = require('@kingjs/enumerable.create');

max.call(sequence(1, 2, 3));
```
result:
```js
3
```
Return the oldest person like this:
```js
var max = require('@kingjs/linq.max');
var sequence = require('@kingjs/enumerable.create');

var compareAge = function(l, r) { return l.age < r.age; }

max.call(sequence(
  { name: 'Alice', age: 18 },
  { name: 'Bob', age: 19 },
  { name: 'Chris', age: 19 },
), compareAge);
```
result:
```js
{ name: 'Bob', age: 19 }
```
## API
```ts
declare function max(
  this: Enumerable,
  lessThan?: (l, r) => boolean
)
```
### Interfaces
- `Enumerable`: See [@kingjs/enumerable.define](https://www.npmjs.com/package/@kingjs/enumerable.define).
### Parameters
- `this`: Sequence to search for max element.
- `lessThan`: Optional element comparison function.
### Return Value
The maximum element.
## Install
With [npm](https://npmjs.org/) installed, run

```
$ npm install @kingjs/linq.max
```

## Acknowledgments
Like [Enumerable.Max](https://msdn.microsoft.com/en-us/library/bb534962(v=vs.110).aspx).

## License

MIT

![Analytics](https://analytics.kingjs.net/linq/max)
npm package: @kingjs/linq.min
Description: Returns the minimum value in a sequence of values projected from elements of a sequence.
Author: Chris King
Latest version: 1.0.6

# @[kingjs](https://www.npmjs.com/package/kingjs)/[linq](https://www.npmjs.com/package/@kingjs/linq).max
Returns the minimum value in a sequence of values projected from elements of a sequence.
## Usage
Return the minimum value of `1`, `2`, `3` like this:
```js
var max = require('@kingjs/linq.max');
var sequence = require('@kingjs/enumerable.create');

max.call(sequence(1, 2, 3));
```
result:
```js
1
```
Return the oldest person like this:
```js
var max = require('@kingjs/linq.max');
var sequence = require('@kingjs/enumerable.create');

var compareAge = function(l, r) { return l.age < r.age; }

max.call(sequence(
  { name: 'Alice', age: 18 },
  { name: 'Bob', age: 18 },
  { name: 'Chris', age: 19 },
), compareAge);
```
result:
```js
{ name: 'Alice', age: 18 }
```
## API
```ts
declare function min(
  this: Enumerable,
  lessThan?: (l, r) => boolean
)
```
### Interfaces
- `Enumerable`: See [@kingjs/enumerable.define](https://www.npmjs.com/package/@kingjs/enumerable.define).
### Parameters
- `this`: Sequence to search for max element.
- `lessThan`: Optional element comparison function.
### Return Value
The minimum element.
## Install
With [npm](https://npmjs.org/) installed, run

```
$ npm install @kingjs/linq.min
```

## Acknowledgments
Like [Enumerable.Min](https://msdn.microsoft.com/en-us/library/bb548741(v=vs.110).aspx).

## License

MIT

![Analytics](https://analytics.kingjs.net/linq/min)
npm package: @kingjs/linq.prepend
Description: Generates an sequence identical to another sequence but with a value added to the start.
Author: Chris King
Latest version: 1.0.6

# @[kingjs](https://www.npmjs.com/package/kingjs)/[linq](https://www.npmjs.com/package/@kingjs/linq).prepend
Generates an sequence identical to another sequence but with a value added to the start.
## Usage
Prepend `0` to the sequence `1`, `2`, `3` like this:
```js
var prepend = require('@kingjs/linq.prepend');
var sequence = require('@kingjs/enumerable.create');
var toArray = require('@kingjs/linq.to-array');

var numbers = sequence(1, 2, 3);

var result = prepend.call(numbers, 0);

toArray.call(result);
```
result:
```js
[0, 1, 2, 3]
```
## API
```ts
declare function prepend(
  this: Enumerable,
  value
): Enumerable
```
### Interfaces
- `Enumerable`: See [@kingjs/enumerable.define](https://www.npmjs.com/package/@kingjs/enumerable.define).
### Parameters
- `this`: A sequence of values. 
- `value`: The value to prepend.
### Return Value
Returns a sequence with `value` prepended.
## Install
With [npm](https://npmjs.org/) installed, run
```
$ npm install @kingjs/linq.prepend
```
## Acknowledgments
Like [Enumerable.Prepend](https://msdn.microsoft.com/en-us/library/mt823357(v=vs.110).aspx)
## License 
MIT

![Analytics](https://analytics.kingjs.net/linq/prepend)
npm package: @kingjs/linq.range
Description: Generate a range of numbers.
Author: Chris King
Latest version: 1.0.11

# @[kingjs](https://www.npmjs.com/package/kingjs)/[linq](https://www.npmjs.com/package/@kingjs/linq).range
Generate a range of numbers.
## Usage
Generate a range of 3 numbers starting at `1`.

```js
var range = require('@kingjs/linq.range');
var toArray = require('@kingjs/linq.to-array');

toArray.call(range(1, 3));
```

result:
```js
[1, 2, 3]
```

## API
```ts
function range(
  start: number, 
  count: number
): Enumerable
```
### Interfaces
- `Enumerable`: See [@kingjs/enumerable.define](https://www.npmjs.com/package/@kingjs/enumerable.define).

### Parameters
- `start`: Number at which to start sequence.
- `count`: Values in sequence.

### Return Value
A sequence of `count` incrementing numbers starting at `start`.

## Install
With [npm](https://npmjs.org/) installed, run

```
$ npm install @kingjs/link.range
```

## Acknowledgments
Like [Enumerable.Range](https://msdn.microsoft.com/en-us/library/system.linq.enumerable.range(v=vs.110).aspx)

## License

MIT

![Analytics](https://analytics.kingjs.net/linq/range)
npm package: @kingjs/linq.repeat
Description: Generate a sequence of a repeated value.
Author: Chris King
Latest version: 1.0.6

# @[kingjs](https://www.npmjs.com/package/kingjs)/[linq](https://www.npmjs.com/package/@kingjs/linq).range
Generate a sequence of a repeated value.
## Usage
Repeat `0` 3 times like this:
```js
var repeat = require('@kingjs/linq.repeat');
var toArray = require('@kingjs/linq.to-array');

toArray.call(repeat(0, 3));
```
result:
```js
[0, 0, 0]
```

## API
```ts
function repeat(
  value: any, 
  count: number
): Enumerable
```
### Interfaces
- `Enumerable`: See [@kingjs/enumerable.define](https://www.npmjs.com/package/@kingjs/enumerable.define).

### Parameters
- `value`: The value to repeat.
- `count`: The number of repetitions.

### Return Value
A sequence of `count` repetitions of `value`.

## Install
With [npm](https://npmjs.org/) installed, run

```
$ npm install @kingjs/link.repeat
```

## Acknowledgments
Like [Enumerable.Repeat](https://msdn.microsoft.com/en-us/library/bb348899(v=vs.110).aspx)

## License

MIT

![Analytics](https://analytics.kingjs.net/linq/repeat)
npm package: @kingjs/linq.select
Description: Generates a sequence of elements composed of elements of another sequence subject to a transform.
Author: Chris King
Latest version: 1.0.7

# @[kingjs](https://www.npmjs.com/package/kingjs)/[linq](https://www.npmjs.com/package/@kingjs/linq).select
Generates a sequence of elements composed of elements of another sequence subject to a transform.
## Usage
Lower the case of `'A'`, `'B'`, `'C'` like this:
```js
var select = require('@kingjs/linq.select');
var sequence = require('@kingjs/enumerable.create');
var toArray = require('@kingjs/linq.to-array');

function selectLowerCase(x) {
  return String.prototype.toLowerCase.call(x);
}

var result = select.call(sequence('A', 'B', 'C'), selectLowerCase);

toArray.call(result);
```
result:
```js
['a', 'b', 'c']
```

## API
```ts
function select(
  this: Enumerable, 
  selector: (x, i) => any
): Enumerable
```
### Interfaces
- `Enumerable`: See [@kingjs/enumerable.define](https://www.npmjs.com/package/@kingjs/enumerable.define).

### Parameters
- `this`: A sequence of element to transform.
- `selector`: A transform applied to each element.
  - `x`: The element to transform.
  - `i`: The index of the element being transformed.

### Return Value
A transformation of each element of the original sequence. 

## Install
With [npm](https://npmjs.org/) installed, run

```
$ npm install @kingjs/link.select
```

## Acknowledgments
Like [Enumerable.Select](https://msdn.microsoft.com/en-us/library/bb548891(v=vs.110).aspx)

## License

MIT

![Analytics](https://analytics.kingjs.net/linq/select)
npm package: @kingjs/linq.select-many
Description: Generate a sequence by concatenating sequences projected from elements of a sequence.
Author: Chris King
Latest version: 1.0.7

# @[kingjs](https://www.npmjs.com/package/kingjs)/[linq](https://www.npmjs.com/package/@kingjs/linq).select-many
Generate a sequence by concatenating sequences projected from elements of a sequence.
## Usage
List all pets and their owners given a list of people and their pets like this:
```js
var selectMany = require('@kingjs/linq.select-many');
var sequence = require('@kingjs/enumerable.create');
var toArray = require('@kingjs/linq.to-array');

var peopleAndPets = sequence(
  { name: 'Alice', pets: sequence('Tiger', 'Butch') },
  { name: 'Bob', pets: sequence('Spike', 'Fluffy') }
);

var petOwners = selectMany.call(
  peopleAndPets,
  function(x, i) { return x.pets; },
  function(x, p) { return x.name + ' owns ' + p; }
)

toArray.call(petOwners);
```
result:
```js
[
  'Alice owns Tiger', 
  'Alice owns Butch', 
  'Bob owns Spike', 
  'Bob owns Fluffy'
]
```

## API
```ts
function selectMany(
  this: Enumerable, 
  collectionSelector?: (x, i) => Enumerable,
  resultSelector?: (x, y) => any
): Enumerable
```
### Interfaces
- `Enumerable`: See [@kingjs/enumerable.define](https://www.npmjs.com/package/@kingjs/enumerable.define).

### Parameters
- `this`: A sequence each element of which can be transformed into another sequence.
- `collectionSelector`: Return a sequence given an element of `this`.
  - `x`: The element to transform into a sequence.
  - `i`: The index of the element being transformed into a sequence.
- `resultSelector`: Transform an element of the sequence derived from `x`.
  - `x`: The element transformed into a sequence of which `y` is a member.
  - `y`: The element of sequence derived from `x` to transform.

### Return Value
A flattened transformed version of the original sequence. 

## Install
With [npm](https://npmjs.org/) installed, run

```
$ npm install @kingjs/link.select-many
```

## Acknowledgments
Like [Enumerable.SelectMany](https://msdn.microsoft.com/en-us/library/bb534732(v=vs.110).aspx)

## License

MIT

![Analytics](https://analytics.kingjs.net/linq/select-many)
npm package: @kingjs/linq.sequence-equal
Description: Returns true if two sequences contain the same number of elements and those that share the same index are equal.
Author: Chris King
Latest version: 1.0.9

# @[kingjs](https://www.npmjs.com/package/kingjs)/[linq](https://www.npmjs.com/package/@kingjs/linq).sequence-equal
Returns true if two sequences contain the same number of elements and those that share the same index are equal.
## Usage
Test if `[1,2,3]` is equal to other arrays like this:
```js
var sequenceEqual = require('@kingjs/linq.sequence-equal');
var sequence = require('@kingjs/enumerable.create');

var expected = sequence(1, 2, 3);

var toFew = sequence(1, 2);
var tooMany = sequence(1, 2, 3, 4);
var wrongOrder = sequence(3, 2, 1);
var justRight = sequence(1, 2, 3);

var result = {
  tooFew: sequenceEqual.call(expected, toFew),
  tooMany: sequenceEqual.call(expected, tooMany),
  wrongOrder: sequenceEqual.call(expected, wrongOrder),
  justRight: sequenceEqual.call(expected, justRight),
};
```

returns:
```js
{
  tooFew: false,
  tooMany: false,
  wrongOrder: false,
  justRight: true
}
```

## API
```ts
declare function sequenceEqual(
    this: Enumerable,
    target: Enumerable,
    equal?: (left, right) => boolean
): boolean
```
### Interfaces
- `Enumerable`: See [@kingjs/enumerable.define](https://www.npmjs.com/package/@kingjs/enumerable.define).

### Parameters
- `this`: the first sequence being compared
- `target`: the second sequence being compared
- `equal`: optional equality predicate.

### Return Value
`true` if both sequences have the same number of elements and corresponding elements compare `==`, otherwise `false`.

## Remarks
The default value for `equal` is exposed by `@kingjs/linq`.

## Install
With [npm](https://npmjs.org/) installed, run

```
$ npm install @kingjs/linq.sequence-equal
```

## Acknowledgments
Like [Enumerable.SequenceEqual](https://msdn.microsoft.com/en-us/library/bb342073(v=vs.110).aspx)

## License

MIT

![Analytics](https://analytics.kingjs.net/linq/sequence-equal)
npm package: @kingjs/linq.single
Description: Returns the only element of a sequence that satisfies a specified condition.
Author: Chris King
Latest version: 1.0.7

# @[kingjs](https://www.npmjs.com/package/kingjs)/[linq](https://www.npmjs.com/package/@kingjs/linq).single
Returns the only element of a sequence that satisfies a specified condition.
## Usage 
Return the single odd number in `0`, `1`, `2` like this:
```js
var singleOrUndefined = require('@kingjs/linq.single');
var sequence = require('@kingjs/enumerable.create');

function isOdd(x) { 
  return x % 2 == 1; 
}

singleOrUndefined.call(sequence(0, 1, 2), isOdd);
```
result:
```js
1
```
## API
```ts
declare function single(
  this: Enumerable,
  predicate?: function(x): boolean
): any
```
### Interfaces
- `Enumerable`: See [@kingjs/enumerable.define](https://www.npmjs.com/package/@kingjs/enumerable.define).

### Parameters
- `this`: The enumerable to search for a single element.
- `predicate`: The predicate with which to test elements.

### Return Value
A single element that satisfies `predicate` else, if more than one or no element satisfies `predicate`, than throws. 

## Install
With [npm](https://npmjs.org/) installed, run

```
$ npm install @kingjs/linq.single
```

## Acknowledgments
Like [`Element.Single`](https://msdn.microsoft.com/en-us/library/bb535118(v=vs.110).aspx).

## License

MIT

![Analytics](https://analytics.kingjs.net/linq/single)
npm package: @kingjs/linq.single-or-undefined
Description: Returns the only element of a sequence that satisfies a specified condition, or undefined.
Author: Chris King
Latest version: 1.0.8

# @[kingjs](https://www.npmjs.com/package/kingjs)/[linq](https://www.npmjs.com/package/@kingjs/linq).single-or-default
Returns the only element of a sequence that satisfies a specified condition, or undefined.
## Usage 
Return the single odd number in `0`, `1`, `2` like this:
```js
var singleOrUndefined = require('@kingjs/linq.single-or-undefined');
var sequence = require('@kingjs/enumerable.create');

function isOdd(x) { 
  return x % 2 == 1; 
}

singleOrUndefined.call(sequence(0, 1, 2), isOdd);
```
result:
```js
1
```
## API
```ts
declare function singleOrDefault(
  this: Enumerable,
  predicate?: function(x): boolean
): any
```
### Interfaces
- `Enumerable`: See [@kingjs/enumerable.define](https://www.npmjs.com/package/@kingjs/enumerable.define).

### Parameters
- `this`: The enumerable to search for a single element.
- `predicate`: The predicate with which to test elements.

### Return Value
A single element that satisfies `predicate` else, if more than one or no element satisfies `predicate`, than undefined. 

## Install
With [npm](https://npmjs.org/) installed, run

```
$ npm install @kingjs/linq.single-or-default
```

## Acknowledgments
Like [`Element.SingleOrDefault`](https://msdn.microsoft.com/en-us/library/bb549274(v=vs.110).aspx).

## License

MIT

![Analytics](https://analytics.kingjs.net/linq/single-or-undefined)
npm package: @kingjs/linq.skip
Description: Generates a sequence identical to another sequence after bypassing a specified number of elements.
Author: Chris King
Latest version: 1.0.8

# @[kingjs](https://www.npmjs.com/package/kingjs)/[linq](https://www.npmjs.com/package/@kingjs/linq).skip
Generates a sequence identical to another sequence after bypassing a specified number of elements.
## Usage 
Skip the first 2 numbers in `-1`, `-1`, `0`, `1`, `2` like this:
```js
var skip = require('@kingjs/linq.skip');
var sequence = require('@kingjs/enumerable.create');
var toArray = require('@kingjs/linq.to-array');

var result = skip.call(sequence(-2, -1, 0, 1, 2), 2);

toArray.call(result);
```
result:
```js
[0, 1, 2]
```
## API
```ts
declare function skip(
  this: Enumerable,
  count: number
): Enumerable
```
### Interfaces
- `Enumerable`: See [@kingjs/enumerable.define](https://www.npmjs.com/package/@kingjs/enumerable.define).

### Parameters
- `this`: The sequence.
- `count`: The number of elements to skip.

### Return Value
A sequence where the first `count` elements have been skipped over. 

## Install
With [npm](https://npmjs.org/) installed, run
```
$ npm install @kingjs/linq.skip
```
## Acknowledgments
Like [`Element.Skip`](https://msdn.microsoft.com/en-us/library/bb358985(v=vs.110).aspx).
## License
MIT

![Analytics](https://analytics.kingjs.net/linq/skip)
npm package: @kingjs/linq.skip-while
Description: Generates a sequence identical to another sequence after bypassing the first contiguous set of elements which satisfy a specified condition.
Author: Chris King
Latest version: 1.0.9

# @[kingjs](https://www.npmjs.com/package/kingjs)/[linq](https://www.npmjs.com/package/@kingjs/linq).skip-while
Generates a sequence identical to another sequence after bypassing the first contiguous set of elements which satisfy a specified condition.
## Usage 
Skip numbers in `-2`, `-1`, `0`, `-1`, `-2` so long as they're negative like this:
```js
var skipWhile = require('@kingjs/linq.skip-while');
var sequence = require('@kingjs/enumerable.create');
var toArray = require('@kingjs/linq.to-array');

function isNegative(x) {
  return x < 0;
}

var result = skipWhile.call(sequence(-2, -1, 0, -1, -2), isNegative);

toArray.call(result);
```
result:
```js
[0, -1, -2]
```
## API
```ts
declare function skipWhile(
  this: Enumerable,
  predicate: function(x, i): boolean
): Enumerable
```
### Interfaces
- `Enumerable`: See [@kingjs/enumerable.define](https://www.npmjs.com/package/@kingjs/enumerable.define).

### Parameters
- `this`: The sequence.
- `predicate`: Predicates elements must satisfy in order to continue skipping elements.
  - `x`: The element to test.
  - `i`: The zero based index of the element.

### Return Value
A sequence where the first elements that satisfy `predicate` have been skipped over. 

## Install
With [npm](https://npmjs.org/) installed, run
```
$ npm install @kingjs/linq.skip-while
```
## Acknowledgments
Like [`Element.SkipWhile`](https://msdn.microsoft.com/en-us/library/bb549288(v=vs.110).aspx).
## License
MIT

![Analytics](https://analytics.kingjs.net/linq/skip-while)
npm package: @kingjs/linq.sum
Description: Computes the sum of a sequence of numbers projected from elements of a sequence.
Author: Chris King
Latest version: 1.0.6

# @[kingjs](https://www.npmjs.com/package/kingjs)/[linq](https://www.npmjs.com/package/@kingjs/linq).sum
Computes the sum of a sequence of numbers projected from elements of a sequence.
## Usage
Sum `1`, `2`, and `3` like this:
```js
var sum = require('@kingjs/linq.sum');
var sequence = require('@kingjs/enumerable.create');

var summation = sum.call(sequence(1, 2, 3));
```
result:
```js
6
```

## API
```ts
declare function sum(
  this: Enumerable
): number;
```
### Interfaces
- `Enumerable`: See [@kingjs/enumerable.define](https://www.npmjs.com/package/@kingjs/enumerable.define).
### Parameters
- `this`: The sequence to sum.
### Return Value
The summation of the sequence.
## Install
With [npm](https://npmjs.org/) installed, run
```
$ npm install @kingjs/linq.sum
```
## Acknowledgments
Like [`Element.Sum`](https://msdn.microsoft.com/en-us/library/bb298381(v=vs.110).aspx).
## License
MIT

![Analytics](https://analytics.kingjs.net/linq/sum)
npm package: @kingjs/linq.take
Description: Generates a sequence identical to another sequence up to a specified index.
Author: Chris King
Latest version: 1.0.8

# @[kingjs](https://www.npmjs.com/package/kingjs)/[linq](https://www.npmjs.com/package/@kingjs/linq).take
Generates a sequence identical to another sequence up to a specified index.
## Usage 
Take the first 2 numbers in `-2`, `-1`, `0`, `1`, `2` like this:
```js
var take = require('@kingjs/linq.take');
var sequence = require('@kingjs/enumerable.create');
var toArray = require('@kingjs/linq.to-array');

var result = take.call(sequence(-2, -1, 0, 1, 2), 2);

toArray.call(result);
```
result:
```js
[-2, -1]
```
## API
```ts
declare function take(
  this: Enumerable,
  count: number
): Enumerable
```
### Interfaces
- `Enumerable`: See [@kingjs/enumerable.define](https://www.npmjs.com/package/@kingjs/enumerable.define).

### Parameters
- `this`: The sequence.
- `count`: The number of elements to take.

### Return Value
A sequence of only the first `count` elements. 

## Install
With [npm](https://npmjs.org/) installed, run
```
$ npm install @kingjs/linq.take
```
## Acknowledgments
Like [`Element.Take`](https://msdn.microsoft.com/en-us/library/bb503062(v=vs.110).aspx).
## License
MIT

![Analytics](https://analytics.kingjs.net/linq/take)
npm package: @kingjs/linq.take-while
Description: Generates a sequence identical to another sequence so long as the elements continue to satisfy a specified condition.
Author: Chris King
Latest version: 1.0.9

# @[kingjs](https://www.npmjs.com/package/kingjs)/[linq](https://www.npmjs.com/package/@kingjs/linq).take-while
Generates a sequence identical to another sequence so long as the elements continue to satisfy a specified condition.
## Usage
Take numbers in `-2`, `-1`, `0`, `-1`, `-2` so long as they're negative like this:
```js
var takeWhile = require('@kingjs/linq.take-while');
var sequence = require('@kingjs/enumerable.create');
var toArray = require('@kingjs/linq.to-array');

function isNegative(x) {
  return x < 0;
}

var result = takeWhile.call(sequence(-2, -1, 0, -1, -2), isNegative);

toArray.call(result);
```
result:
```js
[-2, -1]
```
## API
```ts
declare function takeWhile(
  this: Enumerable,
  predicate: function(x, i): boolean
): Enumerable
```
### Interfaces
- `Enumerable`: See [@kingjs/enumerable.define](https://www.npmjs.com/package/@kingjs/enumerable.define).

### Parameters
- `this`: The sequence.
- `predicate`: Predicates elements must satisfy in order to continue taking elements.
  - `x`: The element to test.
  - `i`: The zero based index of the element.

### Return Value
A sequence where of first elements of `this` that satisfy `predicate`. 

## Install
With [npm](https://npmjs.org/) installed, run
```
$ npm install @kingjs/linq.take-while
```
## Acknowledgments
Like [`Element.TakeWhile`](https://msdn.microsoft.com/en-us/library/bb548775(v=vs.110).aspx).
## License
MIT

![Analytics](https://analytics.kingjs.net/linq/take-while)