@kingjs/linq.first-or-undefined

Returns the first element of a sequence that satisfies a specified condition or a undefined.

Stats

StarsIssuesVersionUpdatedCreatedSize
@kingjs/linq.first-or-undefined
1.0.63 years ago3 years agoMinified + gzip package size for @kingjs/linq.first-or-undefined in KB

Readme

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

var firstOrUndefined = require('@kingjs/linq.first-or-undefined');
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-or-undefined');
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 firstOrUndefined(
  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 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 installed, run

$ npm install @kingjs/linq.first-or-undefined

Acknowledgments

Like Enumerable.FirstOrDefault.

License

MIT

Analytics

If you find any bugs or have a feature request, please open an issue on github!

The npm package download data comes from npm's download counts api and package details come from npms.io.