span -package:rio

span, applied to a predicate p and a list xs, returns a tuple where first element is the longest prefix (possibly empty) of xs of elements that satisfy p and second element is the remainder of the list: span p xs is equivalent to (takeWhile p xs, dropWhile p xs), even if p is _|_.

Laziness

>>> span undefined []
([],[])

>>> fst (span (const False) undefined)
*** Exception: Prelude.undefined

>>> fst (span (const False) (undefined : undefined))
[]

>>> take 1 (fst (span (const True) (1 : undefined)))
[1]
span produces the first component of the tuple lazily:
>>> take 10 (fst (span (const True) [1..]))
[1,2,3,4,5,6,7,8,9,10]

Examples

>>> span (< 3) [1,2,3,4,1,2,3,4]
([1,2],[3,4,1,2,3,4])
>>> span (< 9) [1,2,3]
([1,2,3],[])
>>> span (< 0) [1,2,3]
([],[1,2,3])
span p xs returns the longest prefix of xs that satisfies p, together with the remainder of the stream.
'span' p xs == ('takeWhile' p xs, 'dropWhile' p xs)
xs == ys ++ zs where (ys, zs) = 'span' p xs
Similar to span, returns the longest (possibly empty) prefix of elements satisfying the predicate and the remainder of the string. span p is equivalent to break (not . p) and to (takeWhile p &&& dropWhile p).
span p xs breaks the ByteString into two segments. It is equivalent to (takeWhile p xs, dropWhile p xs)
Similar to span, returns the longest (possibly empty) prefix of elements satisfying the predicate and the remainder of the string. span p is equivalent to break (not . p) and to (takeWhile p &&& dropWhile p).
O(n) span, applied to a predicate p and text t, returns a pair whose first element is the longest prefix (possibly empty) of t of elements that satisfy p, and whose second is the remainder of the text.
>>> T.span (=='0') "000AB"
("000","AB")
Split a string into two parts: the first is the longest prefix that contains only characters that satisfy the predicate; the second part is the rest of the string. Invalid characters are passed as '\0xFFFD' to the predicate.
Split a string into two parts: the first is the longest prefix that contains only characters that satisfy the predicate; the second part is the rest of the string. Invalid characters are passed as '\0xFFFD' to the predicate.
Split a string into two parts: the first is the longest prefix that contains only characters that satisfy the predicate; the second part is the rest of the string. Invalid characters are passed as '\0xFFFD' to the predicate.
span, applied to a predicate p and a list xs, returns a tuple where first element is longest prefix (possibly empty) of xs of elements that satisfy p and second element is the remainder of the list:
>>> span (< 3) [1,2,3,4,1,2,3,4]
([1,2],[3,4,1,2,3,4])

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

>>> span (< 0) [1,2,3]
([],[1,2,3])
span p xs is equivalent to (takeWhile p xs, dropWhile p xs)
Split a bytearray at the point where pred becomes invalid
Combinator for the <span> element. Example:
span $ span $ toHtml "foo"
Result:
<span><span>foo</span></span>
Combinator for the span attribute. Example:
div ! span "bar" $ "Hello."
Result:
<div span="bar">Hello.</div>
It is Data.List.span f undefined = undefined, whereas span f undefined = (undefined, undefined).
forAllPredicates $ \p xs -> Rev.span p xs == swap (mapPair (reverse, reverse) (List.span p (reverse xs)))
forAllPredicates $ \p xs -> Rev.span p xs == (Rev.dropWhile p xs, Rev.takeWhile p xs)
\x xs pad -> defined $ Match.take (pad::[()]) $ fst $ Rev.span ((x::Char)/=) $ cycle $ x:xs
forAllPredicates $ \p xs -> Rev.span p xs == swap (mapPair (reverse, reverse) (List.span p (reverse xs)))
forAllPredicates $ \p xs -> Rev.span p xs == (Rev.dropWhile p xs, Rev.takeWhile p xs)
\x xs pad -> defined $ mapFst length $ Rev.span ((x::Char)/=) $ Match.replicate (pad::[()]) undefined ++ x:xs
Stream elements until one fails the condition, return the rest.
span applies a predicate to a sequence, and returns a tuple where the first element is the longest prefix (possibly empty) that does satisfy the predicate. The second element of the tuple is the remainder of the sequence. span p xs is equivalent to (takeWhile p xs, dropWhile p xs)
> span (< 3) (fromList [1,2,3,4,1,2,3,4] :: Vector Int)
(fromList [1,2],fromList [3,4,1,2,3,4])

> span (< z) (fromList "abc" :: Text)
("abc","")

> span (< 0) 1,2,3
Split ShortText into longest prefix satisfying the given predicate and the remaining suffix.
>>> span (< 'c') "abcdabcd"
("ab","cdabcd")
fst (span p t) <> snd (span p t) == t
Improper lens that splits after the longest consecutive group of bytes that satisfy the given predicate
span p xs breaks the ByteStream into two segments. It is equivalent to (takeWhile p xs, dropWhile p xs).
span p xs breaks the ByteStream into two segments. It is equivalent to (takeWhile p xs, dropWhile p xs)
The equivalent of (takeWhile f xs, dropWhile f xs)
O(n) span, applied to a predicate p and text t, returns a pair whose first element is the longest prefix (possibly empty) of t of elements that satisfy p, and whose second is the remainder of the list.