@kingjs/linq.single

Returns the only element of a sequence that satisfies a specified condition.

Stats

StarsIssuesVersionUpdatedCreatedSize
@kingjs/linq.single
1.0.73 years ago3 years agoMinified + gzip package size for @kingjs/linq.single in KB

Readme

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

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:

1

API

declare function single(
  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 throws.

Install

With npm installed, run

$ npm install @kingjs/linq.single

Acknowledgments

Like Element.Single.

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.