|
![]() |
||||||||||||||
List TutorialFunctions forall and existsFunctions forall(l,cond) i exists(l,cond) check if all/some list elements satisfy given condition. Function forall is almost equivalent to forall(l,f) = l->map(f)->aggregate(operator &&, true); Function exists is equivalent to exists(l,f) = l->map(f)->aggregate(operator ||, false); The difference between library implementations and presented approach is in the library functions property to stop the processing if the result is already determined. Thus, exists stops the list element processing after the first element satisfying the condition is found, while forall stops the list element processing after the first element not satisfying the condition is found. Source code:{# [1,2,3]->forall( operator>(_,1)), [1,2,3]->forall( operator>=(_,1)), [1,2,3]->exists( operator>(_,1)), [1,2,3]->exists( operator<(_,1)) #} Result:{# false, true, true, false #}
|
|
||||||||||||||
© 2006 Saša Malkov | |||||||||||||||