break package:rio

break p is equivalent to span (not . p). Under GHC, a rewrite rule will transform break (==) into a call to the specialised breakByte:
break ((==) x) = breakByte x
break (==x) = breakByte x
break p is equivalent to span (not . p).
break, 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 do not satisfy p and second element is the remainder of the list:
break (> 3) [1,2,3,4,1,2,3,4] == ([1,2,3],[4,1,2,3,4])
break (< 9) [1,2,3] == ([],[1,2,3])
break (> 9) [1,2,3] == ([1,2,3],[])
break p is equivalent to span (not . p).
The break p function is equivalent to span (not . p).
O(n) break is like span, but the prefix returned is over elements that fail the predicate p.
O(n) Split the vector into the longest prefix of elements that do not satisfy the predicate and the rest without copying.
O(n) Split the vector into the longest prefix of elements that do not satisfy the predicate and the rest without copying.
O(n) Split the vector into the longest prefix of elements that do not satisfy the predicate and the rest without copying.
O(n) Split the vector into the longest prefix of elements that do not satisfy the predicate and the rest without copying.
breakEnd behaves like break but from the end of the ByteString breakEnd p == spanEnd (not.p)
Break a string on a substring, returning a pair of the part of the string prior to the match, and the rest of the string. The following relationships hold:
break (== c) l == breakSubstring (singleton c) l
and:
findSubstring s l ==
if null s then Just 0
else case breakSubstring s l of
(x,y) | null y    -> Nothing
| otherwise -> Just (length x)
For example, to tokenise a string, dropping delimiters:
tokenise x y = h : if null t then [] else tokenise x (drop (length x) t)
where (h,t) = breakSubstring x y
To skip to the first occurence of a string:
snd (breakSubstring x y)
To take the parts of a string before a delimiter:
fst (breakSubstring x y)
Note that calling `breakSubstring x` does some preprocessing work, so you should avoid unnecessarily duplicating breakSubstring calls with the same pattern.
where <math> is the breakpoint index. breakl, applied to a predicate p and a sequence xs, returns a pair whose first element is the longest prefix (possibly empty) of xs of elements that do not satisfy p and the second element is the remainder of the sequence. breakl p is equivalent to spanl (not . p).
breakr p is equivalent to spanr (not . p).
O(n+m) Find the first instance of needle (which must be non-null) in haystack. The first element of the returned tuple is the prefix of haystack before needle is matched. The second is the remainder of haystack, starting with the match. Examples:
breakOn "::" "a::b::c" ==> ("a", "::b::c")
breakOn "/" "foobar"   ==> ("foobar", "")
Laws:
append prefix match == haystack
where (prefix, match) = breakOn needle haystack
If you need to break a string by a substring repeatedly (e.g. you want to break on every instance of a substring), use breakOnAll instead, as it has lower startup overhead. This function is strict in its first argument, and lazy in its second. In (unlikely) bad cases, this function's time complexity degrades towards O(n*m).
O(n+m) Find all non-overlapping instances of needle in haystack. Each element of the returned list consists of a pair:
  • The entire string prior to the kth match (i.e. the prefix)
  • The kth match, followed by the remainder of the string
Examples:
breakOnAll "::" ""
==> []
breakOnAll "/" "a/b/c/"
==> [("a", "/b/c/"), ("a/b", "/c/"), ("a/b/c", "/")]
This function is strict in its first argument, and lazy in its second. In (unlikely) bad cases, this function's time complexity degrades towards O(n*m). The needle parameter may not be empty.
O(n+m) Similar to breakOn, but searches from the end of the string. The first element of the returned tuple is the prefix of haystack up to and including the last match of needle. The second is the remainder of haystack, following the match.
breakOnEnd "::" "a::b::c" ==> ("a::b::", "c")
O(n+m) Find the first instance of needle (which must be non-null) in haystack. The first element of the returned tuple is the prefix of haystack before needle is matched. The second is the remainder of haystack, starting with the match. Examples:
>>> breakOn "::" "a::b::c"
("a","::b::c")
>>> breakOn "/" "foobar"
("foobar","")
Laws:
append prefix match == haystack
where (prefix, match) = breakOn needle haystack
If you need to break a string by a substring repeatedly (e.g. you want to break on every instance of a substring), use breakOnAll instead, as it has lower startup overhead. In (unlikely) bad cases, this function's time complexity degrades towards O(n*m).
O(n+m) Find all non-overlapping instances of needle in haystack. Each element of the returned list consists of a pair:
  • The entire string prior to the kth match (i.e. the prefix)
  • The kth match, followed by the remainder of the string
Examples:
>>> breakOnAll "::" ""
[]
>>> breakOnAll "/" "a/b/c/"
[("a","/b/c/"),("a/b","/c/"),("a/b/c","/")]
In (unlikely) bad cases, this function's time complexity degrades towards O(n*m). The needle parameter may not be empty.
O(n+m) Similar to breakOn, but searches from the end of the string. The first element of the returned tuple is the prefix of haystack up to and including the last match of needle. The second is the remainder of haystack, following the match.
>>> breakOnEnd "::" "a::b::c"
("a::b::","c")