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).
break (== c) l == breakSubstring (singleton c) land:
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 yTo 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.
breakOn "::" "a::b::c" ==> ("a", "::b::c") breakOn "/" "foobar" ==> ("foobar", "")Laws:
append prefix match == haystack where (prefix, match) = breakOn needle haystackIf 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).
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.
breakOnEnd "::" "a::b::c" ==> ("a::b::", "c")
>>> breakOn "::" "a::b::c" ("a","::b::c")
>>> breakOn "/" "foobar" ("foobar","")Laws:
append prefix match == haystack where (prefix, match) = breakOn needle haystackIf 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).
>>> 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.
>>> breakOnEnd "::" "a::b::c" ("a::b::","c")