Advanced Functional Prog.

back - up - next


Lists' processing

  1. "Dataflow" operator(s)
    All the preceding functions (map, filter, map2, etc.), and many more, can be found in List module.
    As a complement, these functions can be manipulated more easily with the "pipes" operator(s):
let (|>) x f = f x;;

([1;2] @ [3]) |> List.filter (fun x->(x%2)=0) |> List.map ((+) 1);;

Nb. Most of the functions have remarkable properties usable, for instance, for distributed computing:

List.map f (l1@l2) = (List.map f l1)@(List.map f l2);;

[|1;2;3|] |> Array.Parallel.map ((+) 1);;

Nb. Lists can be easily replaced by Arrays, Sequences, etc. to improve computation times (see. for instance Array.toList or List.ofArray functions).


9