@kingjs/linq.where

1.0.8 • Public • Published

@kingjs/linq.where

Generates a sequence of elements composed of elements from another sequences which satisfy a specified condition.

Usage

Filter 0, 1, 2, 3 to even numbers like this:

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

var numbers = sequence(0, 1, 2, 3);

var isEven = function (x) { return x % 2 == 0; }

var evenNumbers = where.call(numbers, isEven);

toArray.call(evenNumbers);

result:

[0, 2]

Filter out every other element in 'a', 'b', 'c', 'd' like this:

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

var letters = sequence('a', 'b', 'c', 'd');

var isEvenIndex = function (x, i) { return i % 2 == 0; }

var everyOther = where.call(letters, isEvenIndex);

toArray.call(everyOther);

result:

['a', 'c']

API

declare function where(
  this: Enumerable,
  predicate: (x, i) => boolean,
): Enumerable

Interfaces

Parameters

  • this: The sequence to filter.
  • predicate: The filtering predicate.
    • x: The value being considered for inclusion.
    • i: The index of the value being considered.

Return Value

A sequence filtered by the predicate.

Install

With npm installed, run

$ npm install @kingjs/linq.where

Acknowledgments

Like Enumerable.Where.

License

MIT

Analytics

Readme

Keywords

none

Package Sidebar

Install

npm i @kingjs/linq.where

Weekly Downloads

11

Version

1.0.8

License

MIT

Unpacked Size

4.02 kB

Total Files

4

Last publish

Collaborators

  • kingces95