|
![]() |
||||||||||||||
List TutorialFunction filterMapFunction filterMap(l,cond,f) is a combination of functions filter and map. It maps elements of list l by function f to a new list, but only including elements that satisfy condition cond. The element order is preserved. Function filterMap(l,cond,f) is equivalent to filterMap(l,cond,f) = l->filter(cond)->map(f); but is more efficient, because it processes list l only once, with no construction of intermediate list. Source code:{# [1,2,3,4,5]->filter(\x : x%2>0)->map(\x : x*x), [1,2,3,4,5]->filterMap(\x : x%2>0,\x : x*x), [1,2,3,4,5]->filter(\x : x%2>0), [1,2,3,4,5]->filterMap(\x : x%2>0,\x:x), [3,4,5]->map(\x : x*x), [3,4,5]->filterMap(\x : true,\x : x*x) #} Result:{# [1,9,25], [1,9,25], [1,3,5], [1,3,5], [9,16,25], [9,16,25] #}
|
|
||||||||||||||
© 2006 Saša Malkov | |||||||||||||||