1.0.8 • Published 7 years ago

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

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

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

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:

1

API

declare function singleOrDefault(
  this: Enumerable,
  predicate?: function(x): boolean
): any

Interfaces

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

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

Acknowledgments

Like Element.SingleOrDefault.

License

MIT

Analytics

1.0.8

7 years ago

1.0.7

7 years ago

1.0.6

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago