1.0.7 • Published 6 years ago

@kingjs/linq.first v1.0.7

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

@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;

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

firstOrUndefined.call(sequence(0, 1, 2));

result:

0

Return the first odd value of 0, 1, 2 like this;

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:

1

API

declare function first(
  this: Enumerable,
  predicate?: (x) => boolean
)

Interfaces

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 installed, run

$ npm install @kingjs/linq.first

Acknowledgments

Like Enumerable.First.

License

MIT

Analytics

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