takeWhile -package:attoparsec

takeWhile, applied to a predicate p and a list xs, returns the longest prefix (possibly empty) of xs of elements that satisfy p.

Laziness

>>> takeWhile (const False) undefined
*** Exception: Prelude.undefined
>>> takeWhile (const False) (undefined : undefined)
[]
>>> take 1 (takeWhile (const True) (1 : undefined))
[1]

Examples

>>> takeWhile (< 3) [1,2,3,4,1,2,3,4]
[1,2]
>>> takeWhile (< 9) [1,2,3]
[1,2,3]
>>> takeWhile (< 0) [1,2,3]
[]
takeWhile p xs returns the longest prefix of the stream xs for which the predicate p holds.
Similar to takeWhile, returns the longest (possibly empty) prefix of elements satisfying the predicate.
takeWhile, applied to a predicate p and a ByteString xs, returns the longest prefix (possibly empty) of xs of elements that satisfy p.
Similar to takeWhile, returns the longest (possibly empty) prefix of elements satisfying the predicate.
O(n) takeWhile, applied to a predicate p and a Text, returns the longest prefix (possibly empty) of elements that satisfy p.
takeWhile, applied to a predicate p and a stream, returns the longest prefix (possibly empty) of elements that satisfy p. Properties
unstream . takeWhile p . stream = takeWhile p
Stream all values downstream that match the given predicate. Same caveats regarding downstream termination apply as with take.
takeWhile, applied to a predicate p and a list xs, returns the longest prefix (possibly empty) of xs of elements that satisfy p.
>>> takeWhile (< 3) [1,2,3,4,1,2,3,4]
[1,2]

>>> takeWhile (< 9) [1,2,3]
[1,2,3]

>>> takeWhile (< 0) [1,2,3]
[]
Take bytes while the @predicate hold from the current position in the stream
Return all bytes while the predicate returns True. Since 0.3.0
Since 1.0.8
(takeWhile p) allows values to pass downstream so long as they satisfy the predicate p.
takeWhile (pure True) = cat

takeWhile (liftA2 (&&) p1 p2) = takeWhile p1 >-> takeWhile p2
Alternative version of reverse . takeWhile p . reverse.
forAllPredicates $ \p xs -> Rev.takeWhile p xs == reverse (List.takeWhile p (reverse xs))
forAllPredicates $ \p xs -> Rev.takeWhile p xs == reverse (List.takeWhile p (reverse xs))
\x xs pad -> defined $ Rev.takeWhile ((x::Char)/=) $ Match.replicate (pad::[()]) undefined ++ x:xs
End stream when an element fails a condition; the original return value is lost. By contrast span preserves this information, and is generally more desirable.
S.takeWhile thus = void . S.span thus
To preserve the information - but thus also force the rest of the stream to be developed - write
S.drained . S.span thus
as dropWhile thus is
S.effects . S.span thus
takeWhile, applied to a predicate p and a ByteString xs, returns the longest prefix (possibly empty) of xs of elements that satisfy p.
takeWhile, applied to a predicate p and a list xs, returns the longest prefix (possibly empty) of xs of elements that satisfy p:
takeWhile (< 3) [1,2,3,4,1,2,3,4] == [1,2]
takeWhile (< 9) [1,2,3] == [1,2,3]
takeWhile (< 0) [1,2,3] == []
O(n) takeWhile, applied to a predicate p and a Text, returns the longest prefix (possibly empty) of elements that satisfy p. Subject to fusion.
O(n) Yield the longest prefix of elements satisfying the predicate. Current implementation is not copy-free, unless the result vector is fused away.
O(n) Yield the longest prefix of elements satisfying the predicate. Current implementation is not copy-free, unless the result vector is fused away.
O(n) Yield the longest prefix of elements satisfying the predicate. Current implementation is not copy-free, unless the result vector is fused away.
O(n) Yield the longest prefix of elements satisfying the predicate. Current implementation is not copy-free, unless the result vector is fused away.
takeWhile applies a predicate to a sequence, and returns the longest prefix (possibly empty) of the sequence of elements that satisfy the predicate.
> takeWhile (< 3) [1,2,3,4,5,1,2,3]
[1,2]

> takeWhile (< z) (fromList "abc" :: Text)
"abc"