@kingjs/linq.take-while

Generates a sequence identical to another sequence so long as the elements continue to satisfy a specified condition.

Stats

stars 🌟issues ⚠️updated 🛠created 🐣size 🏋️‍♀️
04Jun 21, 2021Jul 20, 2018Minified + gzip package size for @kingjs/linq.take-while in KB

Readme

@kingjs/linq.take-while

Generates a sequence identical to another sequence so long as the elements continue to satisfy a specified condition.

Usage

Take numbers in -2, -1, 0, -1, -2 so long as they're negative like this:

var takeWhile = require('@kingjs/linq.take-while');
var sequence = require('@kingjs/enumerable.create');
var toArray = require('@kingjs/linq.to-array');

function isNegative(x) {
  return x < 0;
}

var result = takeWhile.call(sequence(-2, -1, 0, -1, -2), isNegative);

toArray.call(result);

result:

[-2, -1]

API

declare function takeWhile(
  this: Enumerable,
  predicate: function(x, i): boolean
): Enumerable

Interfaces

Parameters

  • this: The sequence.
  • predicate: Predicates elements must satisfy in order to continue taking elements.
    • x: The element to test.
    • i: The zero based index of the element.

Return Value

A sequence where of first elements of this that satisfy predicate.

Install

With npm installed, run

$ npm install @kingjs/linq.take-while

Acknowledgments

Like Element.TakeWhile.

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.