splitOn

O(m+n) Break a Text into pieces separated by the first Text argument (which cannot be empty), consuming the delimiter. An empty delimiter is invalid, and will cause an error to be raised. Examples:
>>> splitOn "\r\n" "a\r\nb\r\nd\r\ne"
["a","b","d","e"]
>>> splitOn "aaa"  "aaaXaaaXaaaXaaa"
["","X","X","X",""]
>>> splitOn "x"    "x"
["",""]
and
intercalate s . splitOn s         == id
splitOn (singleton c)             == split (==c)
(Note: the string s to split on above cannot be empty.) In (unlikely) bad cases, this function's time complexity degrades towards O(n*m).
O(m+n) Break a Text into pieces separated by the first Text argument (which cannot be an empty string), consuming the delimiter. An empty delimiter is invalid, and will cause an error to be raised. Examples:
splitOn "\r\n" "a\r\nb\r\nd\r\ne" == ["a","b","d","e"]
splitOn "aaa"  "aaaXaaaXaaaXaaa"  == ["","X","X","X",""]
splitOn "x"    "x"                == ["",""]
and
intercalate s . splitOn s         == id
splitOn (singleton c)             == split (==c)
(Note: the string s to split on above cannot be empty.) 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).
Split on the given sublist. Equivalent to split . dropDelims . onSublist.
>>> splitOn ":" "12:35:07"
["12","35","07"]
>>> splitOn "x" "axbxc"
["a","b","c"]
>>> splitOn "x" "axbxcx"
["a","b","c",""]
>>> splitOn ".." "a..b...c....d.."
["a","b",".c","","d",""]
In some parsing combinator frameworks this is also known as sepBy. Note that this is the right inverse of the intercalate function from Data.List, that is,
intercalate x . splitOn x === id
splitOn x . intercalate x is the identity on certain lists, but it is tricky to state the precise conditions under which this holds. (For example, it is not enough to say that x does not occur in any elements of the input list. Working out why is left as an exercise for the reader.)
Break a list into pieces separated by the first list argument, consuming the delimiter. An empty delimiter is invalid, and will cause an error to be raised.
splitOn "\r\n" "a\r\nb\r\nd\r\ne" == ["a","b","d","e"]
splitOn "aaa"  "aaaXaaaXaaaXaaa"  == ["","X","X","X",""]
splitOn "x"    "x"                == ["",""]
splitOn "x"    ""                 == [""]
\s x -> s /= "" ==> intercalate s (splitOn s x) == x
\c x -> splitOn [c] x                           == split (==c) x
Splits an InputStream over ByteStrings using a delimiter predicate. Note that:
  • data pushed back with unRead is *not* propagated upstream here.
  • the resulting InputStream may hold an unbounded amount of the bytestring in memory waiting for the function to return true, so this function should not be used in unsafe contexts.
  • the delimiter is NOT included in the output.
  • consecutive delimiters are not merged.
  • if the input ends in the delimiter, a final empty string is not emitted. (/Since: 1.5.0.0. Previous versions had the opposite behaviour, which was changed to match lines./)
Example:
ghci> Streams.fromList ["the quick br", "own  fox"::ByteString] >>=
Streams.splitOn (== ' ') >>= Streams.toList
["the","quick","brown","","fox"]
O(m+n) Break a Text into pieces separated by the first Text argument (which cannot be an empty string), consuming the delimiter. An empty delimiter is invalid, and will cause an error to be raised. Examples:
splitOn "\r\n" "a\r\nb\r\nd\r\ne" == ["a","b","d","e"]
splitOn "aaa"  "aaaXaaaXaaaXaaa"  == ["","X","X","X",""]
splitOn "x"    "x"                == ["",""]
and
intercalate s . splitOn s         == id
splitOn (singleton c)             == split (==c)
(Note: the string s to split on above cannot be empty.) 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(m+n) Break a Text into pieces separated by the first Text argument (which cannot be empty), consuming the delimiter. An empty delimiter is invalid, and will cause an error to be raised. Examples:
>>> splitOn "\r\n" "a\r\nb\r\nd\r\ne"
["a","b","d","e"]
>>> splitOn "aaa"  "aaaXaaaXaaaXaaa"
["","X","X","X",""]
>>> splitOn "x"    "x"
["",""]
and
intercalate s . splitOn s         == id
splitOn (singleton c)             == split (==c)
(Note: the string s to split on above cannot be empty.) In (unlikely) bad cases, this function's time complexity degrades towards O(n*m).
Split a list into sublists delimited by the given element.
Split a byte stream into groups separated by the given ByteString
O(m+n) Break a JSString into pieces separated by the first JSString argument (which cannot be empty), consuming the delimiter. An empty delimiter is invalid, and will cause an error to be raised. Examples:
splitOn "\r\n" "a\r\nb\r\nd\r\ne" == ["a","b","d","e"]
splitOn "aaa"  "aaaXaaaXaaaXaaa"  == ["","X","X","X",""]
splitOn "x"    "x"                == ["",""]
and
intercalate s . splitOn s         == id
splitOn (singleton c)             == split (==c)
(Note: the string s to split on above cannot be empty.) In (unlikely) bad cases, this function's time complexity degrades towards O(n*m).
Split on an infixed separator element, dropping the separator. The supplied Fold is applied on the split segments. Splits the stream on separator elements determined by the supplied predicate, separator is considered as infixed between two segments:
>>> splitOn' p xs = Stream.toList $ Stream.splitOn p Fold.toList (Stream.fromList xs)

>>> splitOn' (== '.') "a.b"
["a","b"]
An empty stream is folded to the default value of the fold:
>>> splitOn' (== '.') ""
[""]
If one or both sides of the separator are missing then the empty segment on that side is folded to the default output of the fold:
>>> splitOn' (== '.') "."
["",""]
>>> splitOn' (== '.') ".a"
["","a"]
>>> splitOn' (== '.') "a."
["a",""]
>>> splitOn' (== '.') "a..b"
["a","","b"]
splitOn is an inverse of intercalating single element:
Stream.intercalate (Stream.fromPure '.') Unfold.fromList . Stream.splitOn (== '.') Fold.toList === id
Assuming the input stream does not contain the separator:
Stream.splitOn (== '.') Fold.toList . Stream.intercalate (Stream.fromPure '.') Unfold.fromList === id
Split on an infixed separator element, dropping the separator. The supplied Fold is applied on the split segments. Splits the stream on separator elements determined by the supplied predicate, separator is considered as infixed between two segments:
>>> splitOn' p xs = Stream.fold Fold.toList $ Stream.splitOn p Fold.toList (Stream.fromList xs)

>>> splitOn' (== '.') "a.b"
["a","b"]
An empty stream is folded to the default value of the fold:
>>> splitOn' (== '.') ""
[""]
If one or both sides of the separator are missing then the empty segment on that side is folded to the default output of the fold:
>>> splitOn' (== '.') "."
["",""]
>>> splitOn' (== '.') ".a"
["","a"]
>>> splitOn' (== '.') "a."
["a",""]
>>> splitOn' (== '.') "a..b"
["a","","b"]
splitOn is an inverse of intercalating single element:
Stream.intercalate (Stream.fromPure '.') Unfold.fromList . Stream.splitOn (== '.') Fold.toList === id
Assuming the input stream does not contain the separator:
Stream.splitOn (== '.') Fold.toList . Stream.intercalate (Stream.fromPure '.') Unfold.fromList === id
Split the array into a stream of slices using a predicate. The element matching the predicate is dropped. Pre-release
Split a stream of arrays on a given separator byte, dropping the separator and coalescing all the arrays between two separators into a single array.
Generate a stream of array slices using a predicate. The array element matching the predicate is dropped. Pre-release
Split on the input string using the predicate as separator e.g.
splitOn (== ',') ","          == ["",""]
splitOn (== ',') ",abc,"      == ["","abc",""]
splitOn (== ':') "abc"        == ["abc"]
splitOn (== ':') "abc::def"   == ["abc","","def"]
splitOn (== ':') "::abc::def" == ["","","abc","","def"]
The reader that splits a string into a list of strings consuming the separator.
Split on a specific elements returning a list of colletion
splitOn single n cs will force expansion of catch-alls if single.
Split on the given sublist. Equivalent to split . dropDelims . onSublist. For example:
>>> splitOn (BV.fromList "..") (BV.fromList "a..b...c....d..")
["a","b",".c","","d",""]
In some parsing combinator frameworks this is also known as sepBy. Note that this is the right inverse of the intercalate function from Data.List, that is,
> \xs -> (intercalate xs . splitOn xs) === id
splitOn x . intercalate x is the identity on certain lists, but it is tricky to state the precise conditions under which this holds. (For example, it is not enough to say that x does not occur in any elements of the input list. Working out why is left as an exercise for the reader.)
Calling splitOn needle haystack will split haystack into a list of substrings using needle as the delimiter. https://github.com/haskell/bytestring/issues/100