Portage of .NET Enumerable class of linq to nodejs.
npm install linqy
var linqy = require('linqy');
var e = linqy.e;
To use the API the first thing you want to do, is transform your array into an enumerable:
var enumerable = e([1,2,3,4,5]);
Note that if you are using typescript, the type of enumerable will be inferred to linqy.Enumerable.
Then with an enumerable you can call a load of useful functions:
Apply an accumulator function, starting with the seed.
- predicate: a function taking two arguments, the aggregate so far and the current element to aggregate, and returning the aggregated result.
- seed optional: the seed to start aggregating against.
Returns: the final aggregate.
Determines whether all elements satisfy a condition.
- predicate: a function taking the current element to test, returning a boolean.
Returns: a boolean.
Determines whether any elements satisfy a condition.
- predicate: a function taking the current element to test, returning a boolean.
Returns: a boolean.
Computes the average value of the elements.
- predicate optional: a function taking the current element to transform to a number, returning that number.
Returns: a number.
Typescript usage only.
Cast the generic type of the enumerable.
- U: the type to cast to.
Returns: a linqy.Enumerable.
Concatenates with another enumerable.
- enumerable: an enumerable or simple array to concatenate.
Returns: a linqy enumerable.
Determines whether an item is contained.
- item: an item to check.
Returns: a boolean.
Returns the number of elements satisfying a predicate.
- predicate optional: a function taking the current element to test, returning a boolean.
Returns: a number.
Returns distinct elements by using a predicate to establish the distinction criterion.
- predicate optional: a function taking the current element to transform to its distinction criterion.
Returns: a linqy enumerable.
Returns the element at the given position.
Returns: the item.
Returns an empty enumerable. Very handy in a typescript context.
Returns: an empty linqy enumerable.
Produces the difference with another enumerable, containing items not available in the two enumerables.
- enumerable: an enumerable or simple array to compare with.
Returns: A linqy enumerable.
Returns the first element satisfying a predicate.
- predicate: a function taking the current element to test, returning a boolean.
Returns: the item.
Calls a function on every items.
- action: a function taking the current element.
Returns: nothing.
Groups the elements by using a predicate to establish the grouping value.
- predicate: a function taking the current element to transform to its grouping value.
Returns: a linqy enumerable of grouping object. The grouping object has a key field representing the grouping value, it is an linqy enumerable itself of the items within the group.
Produces the intersection with another enumerable, containing items only available in the two enumerables.
- enumerable: an enumerable or simple array to compare with.
Returns: A linqy enumerable.
Correlates the elements with another enumerable by using predicates to establish matching keys and result.
- inner: an enumerable or simple array to compare with.
- outerSelector: a function taking the current outer element to transform to its matching value.
- innerSelector: a function taking the current inner element to transform to its grouping value.
- resultSelector: a function taking two arguments, the matching outer and inner items, and returning the joined result.
Returns: A linqy enumerable.
Returns the last element satisfying a predicate.
- predicate: a function taking the current element to test, returning a boolean.
Returns: the item.
Returns the item having the maximum decimal value by using a predicate to establish the decimal value.
- predicate optional: a function taking the current element to evaluate, returning a number.
Returns: the item.
Returns the item having the minimum decimal value by using a predicate to establish the decimal value.
- predicate optional: a function taking the current element to evaluate, returning a number.
Returns: the item.
Sorts the items in an ascending order by using a predicate to establish the sorting value.
- predicate optional: a function taking the current element to transform to its sorting value.
Returns: a linqy enumerable.
Sorts the items in a descending order by using a predicate to establish the sorting value.
- predicate optional: a function taking the current element to transform to its sorting value.
Returns: a linqy enumerable.
Inverts the order of the items.
Returns: a linqy enumerable.
Transforms each items by using a predicate.
- predicate: a function taking the current element to transform to its projected value.
Returns: a linqy enumerable.
Transforms each items by using a predicate and flattens it into a single enumerable.
- predicate: a function taking the current element to transform to its projected enumerable value.
Return: a linqy enumerable.
Returns the only element satisfying a predicate, throwing an exception if no or more that on element is available.
- predicate: a function taking the current element to test, returning a boolean.
Returns: the item.
Bypasses the specified number of elements, keeping the remaining ones.
- number: the number of items to skip.
Return: a linqy enumerable.
Bypasses the elements while they are satisfying a predicate, keeping the remaining ones.
- predicate: a function taking the current element to test, returning a boolean.
Return: a linqy enumerable.
Computes the sum of the elements.
- predicate optional: a function taking the current element to transform to a number, returning that number.
Returns: a number.
Keeps the specified number of elements, ignoring the remaining ones.
- number: the number of items to take.
Return: a linqy enumerable.
Keeps the elements while they are satisfying a predicate, ignoring the remaining ones.
- predicate: a function taking the current element to test, returning a boolean.
Return: a linqy enumerable.
Subsequent sorts the items in an ascending order by using a predicate to establish the sorting value.
- predicate optional: a function taking the current element to transform to its sorting value.
Returns: a linqy enumerable.
Subsequent sorts the items in a descending order by using a predicate to establish the sorting value.
- predicate optional: a function taking the current element to transform to its sorting value.
Returns: a linqy enumerable.
Produces the union with another enumerable, containing distinct items available in the two enumerables.
- enumerable: an enumerable or simple array to compare with.
Returns: A linqy enumerable.
Creates an array from the current enumerable.
Returns: plain array.
Filter the items by keeping elements satisfying a condition.
- predicate: a function taking the current element to test, returning a boolean.
Returns: a linqy enumerable.
Merge with another enumerable by using a predicate.
- enumerable: an enumerable or simple array to compare with.
- resultSelector: a function taking two arguments, the items at the same positions, and returning the joined result.
Returns: a linqy enumerable.