|
![]() |
||||||||||||||
List TutorialFunction filterFunction filter(l,cond) computes the list of elements of l that satisfy given condition. The element order is preserved. Function forall is equivalent to filter(l,cond) = if l->empty() then [] else if l->hd()->cond() then l->hd():l->tl()->filter(cond) else l->tl()->filter(cond); Source code:{# [1,2,3,4,5]->filter( operator>(_,1)), [1,2,3,4,5]->filter( \x : x%2>0 ), // even numbers [1,2,3,4,5]->filter( \x : x%2=0 ) // odd numbers #} Result:{# [2,3,4,5], [1,3,5], [2,4] #}
|
|
||||||||||||||
© 2006 Saša Malkov | |||||||||||||||