Skip to content

TakeWhile

Status: Stable

documented, exercised by the test suite and/or worked examples, with no known limitations recorded.

Description

TakeWhile[list, crit]

Gives the longest leading run of elements e for which crit[e] is True. Over an association, tests the values and keeps the matching leading entries (keys preserved).

Examples (2)

Every input below was run against the current Mathilda build and its output recorded.

Basic examples (2)

In[1]:= TakeWhile[<|"a" -> 1, "b" -> 2, "c" -> 5, "d" -> 1|>, # < 3 &]
Out[1]= <|"a" -> 1, "b" -> 2|>

In[2]:= LengthWhile[<|"a" -> 1, "b" -> 2, "c" -> 5|>, # < 3 &]
Out[2]= 2

Implementation notes

Attributes: Protected.

References

See also: LengthWhile