Lambda

You are viewing an old version of this entry, click here to see latest version.
class LambdaAvailable in flash8, flash, neko, js, php, cpp, cs, java

The Lambda class is a collection of functional methods in order to use functional-style programming with Haxe.

Articles with more information on Lambda: The Great Lambda , map & filter , flash9 Lambda.map example

static function array<A>( it : Iterable<A> ) : Array<A>Creates an Array from an Iterable static function concat<T>( a : Iterable<T>, b : Iterable<T> ) : List<T>Returns a list containing all items of 'a' followed by all items of 'b' static function count<A>( it : Iterable<A>, ?pred : A -> Bool ) : IntCount the number of elements in an Iterable static function empty( it : Iterable<Dynamic> ) : BoolTells if an iterable does not contain any element. static function exists<A>( it : Iterable<A>, f : A -> Bool ) : BoolTells if at least one element of the iterable is found by using the specific function. static function filter<A>( it : Iterable<A>, f : A -> Bool ) : List<A>Return the list of elements matching the function 'f'
Usage Examples
static function fold<A, B>( it : Iterable<A>, f : A -> B -> B, first : B ) : BFunctional 'fold' using an Iterable static function foreach<A>( it : Iterable<A>, f : A -> Bool ) : BoolTells if all elements of the iterable have the specified property defined by f. If there is no element, returns true. static function has<A>( it : Iterable<A>, elt : A, ?cmp : A -> A -> Bool ) : BoolTells if the element is part of an iterable. The comparison is made using the "==" operator. Optionally you can pass as a third parameter a function that performs the comparison. That function must take as arguments the two items to compare and returns a boolean value.
Examples
static function indexOf<T>( it : Iterable<T>, v : T ) : IntReturns the index of the item in the given Iterable, depending on the order of the Iterator. Returns -1 if the item was not found. static function iter<A>( it : Iterable<A>, f : A -> Void ) : VoidCall the function 'f' on all elements of the Iterable 'it'. static function list<A>( it : Iterable<A> ) : List<A>Creates a List from an Iterable static function map<A, B>( it : Iterable<A>, f : A -> B ) : List<B>Creates a new List by applying the function 'f' to all elements of the iterable 'it'. static function mapi<A, B>( it : Iterable<A>, f : Int -> A -> B ) : List<B>Similar to map, but also pass an index for each item iterated.
version #15310, modified 2012-08-10 03:24:41 by jan_flanders
0 comment