1.0.8 • Published 6 years ago

@kingjs/linq.last-or-undefined v1.0.8

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

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

var lastOrUndefined = require('@kingjs/linq.last-or-undefined');
var sequence = require('@kingjs/enumerable.create');

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

result:

2

Return the last odd value of 0, 1, 2, 3, 4 like this;

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:

3

API

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

Interfaces

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

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

Acknowledgments

Like Enumerable.LastOrDefault.

License

MIT

Analytics

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