Navigation
Synopsis Take elements from the front of the list as long as a predicate is true.
Function list[&T] takeWhile(list[&T] lst, bool (&T a) take)
Usage import List;
Examples
rascal>import List;
ok
rascal>bool isEven(int a) = a mod 2 == 0;
bool (int): bool isEven(int);
rascal>takeWhile([2,4,6,8,1,2,3,4,5],isEven);
list[int]: [2,4,6,8]

Questions
Question [1].
The type of takeWhile([5], bool(int x){ return x > 0;}) is

Question [2].
takeWhile([12, -2, -13, -18], bool(int x){ return x > 0;}) == 

Question [3].
takeWhile([-17, -3, -15, -10], ) == [-17,-3,-15,-10]



Is this page unclear, or have you spotted an error? Please add a comment below and help us to improve it. For all other questions and remarks, visit ask.rascal-mpl.org.