The

`Lambda`

class is a collection of methods to support functional programming. It is ideally used with`using Lambda`

and then acts as an extension to Iterable types.On static platforms, working with the Iterable structure might be slower than performing the operations directly on known types, such as Array and List.

If the first argument to any of the methods is null, the result is unspecified.

See:

`static array<A> (it:Iterable<A>):Array<A>`

Creates an Array from Iterable `it`

.

If `it`

is an Array, this function returns a copy of it.

`static concat<T> (a:Iterable<T>, b:Iterable<T>):List<T>`

Returns a new List containing all elements of Iterable `a`

followed by all elements of Iterable `b`

.

If `a`

or `b`

are null, the result is unspecified.

`static count<A> (it:Iterable<A>, ?pred:A ‑> Bool):Int`

Returns the number of elements in `it`

for which `pred`

is true, or the total number of elements in `it`

if `pred`

is null.

This function traverses all elements.

`static empty<T> (it:Iterable<T>):Bool`

Tells if Iterable `it`

does not contain any element.

`static exists<A> (it:Iterable<A>, f:A ‑> Bool):Bool`

Tells if `it`

contains an element for which `f`

is true.

This function returns true as soon as an element is found for which a call to `f`

returns true.

If no such element is found, the result is false.

If `f`

is null, the result is unspecified.

`static filter<A> (it:Iterable<A>, f:A ‑> Bool):List<A>`

Returns a List containing those elements of `it`

for which `f`

returned true.

If `it`

is empty, the result is the empty List even if `f`

is null.

Otherwise if `f`

is null, the result is unspecified.

`static find<T> (it:Iterable<T>, f:T ‑> Bool):Null<T>`

Returns the first element of `it`

for which `f`

is true.

This function returns as soon as an element is found for which a call to `f`

returns true.

If no such element is found, the result is null.

If `f`

is null, the result is unspecified.

`static flatMap<A, B> (it:Iterable<A>, f:A ‑> Iterable<B>):List<B>`

A composition of map and flatten.

The order of elements is preserved.

If `f`

is null, the result is unspecified.

`static flatten<A> (it:Iterable<Iterable<A>>):List<A>`

Concatenate a list of lists.

The order of elements is preserved.

`static fold<A, B> (it:Iterable<A>, f:A ‑> B ‑> B, first:B ):B `

Functional fold on Iterable `it`

, using function `f`

with start argument `first`

.

If `it`

has no elements, the result is `first`

.

Otherwise the first element of `it`

is passed to `f`

alongside `first`

. The result of that call is then passed to `f`

with the next element of `it`

, and so on until `it`

has no more elements.

If `it`

or `f`

are null, the result is unspecified.

`static foreach<A> (it:Iterable<A>, f:A ‑> Bool):Bool`

Tells if `f`

is true for all elements of `it`

.

This function returns false as soon as an element is found for which a call to `f`

returns false.

If no such element is found, the result is true.

In particular, this function always returns true if `it`

is empty.

If `f`

is null, the result is unspecified.

`static has<A> (it:Iterable<A>, elt:A ):Bool`

Tells if `it`

contains `elt`

.

This function returns true as soon as an element is found which is equal to `elt`

according to the `==`

operator.

If no such element is found, the result is false.

`static indexOf<T> (it:Iterable<T>, v:T ):Int`

Returns the index of the first element `v`

within Iterable `it`

.

This function uses operator `==`

to check for equality.

If `v`

does not exist in `it`

, the result is -1.

`static iter<A> (it:Iterable<A>, f:A ‑> Void):Void`

Calls `f`

on all elements of `it`

, in order.

If `f`

is null, the result is unspecified.

`static list<A> (it:Iterable<A>):List<A>`

Creates a List form Iterable `it`

.

If `it`

is a List, this function returns a copy of it.

`static map<A, B> (it:Iterable<A>, f:A ‑> B ):List<B>`

Creates a new List by applying function `f`

to all elements of `it`

.

The order of elements is preserved.

If `f`

is null, the result is unspecified.

`static mapi<A, B> (it:Iterable<A>, f:Int ‑> A ‑> B ):List<B>`

Similar to map, but also passes the index of each element to `f`

.

The order of elements is preserved.

If `f`

is null, the result is unspecified.

© 2005–2018 Haxe Foundation

Licensed under a MIT license.

https://api.haxe.org/Lambda.html