:: (a -> Bool) -> [a] -> [[a]] -package:utility-ht

Split on elements satisfying the given predicate. Equivalent to split . dropDelims . whenElt.
>>> splitWhen (<0) [1,3,-4,5,7,-9,0,2]
[[1,3],[5,7],[0,2]]
>>> splitWhen (<0) [1,-2,3,4,-5,-6,7,8,-9]
[[1],[3,4],[],[7,8],[]]
Split into "words", with word boundaries indicated by the given predicate. Satisfies words === wordsBy isSpace; equivalent to split . dropBlanks . dropDelims . whenElt.
>>> wordsBy (`elem` ",;.?! ") "Hello there, world! How?"
["Hello","there","world","How"]
>>> wordsBy (=='x') "dogxxxcatxbirdxx"
["dog","cat","bird"]
Split into "lines", with line boundaries indicated by the given predicate. Satisfies lines === linesBy (=='n'); equivalent to split . dropFinalBlank . dropDelims . whenElt.
>>> linesBy (==';') "foo;bar;;baz;"
["foo","bar","","baz"]
>>> linesBy (=='x') "dogxxxcatxbirdxx"
["dog","","","cat","bird",""]
A variant of words with a custom test. In particular, adjacent separators are discarded, as are leading or trailing separators.
wordsBy (== ':') "::xyz:abc::123::" == ["xyz","abc","123"]
\s -> wordsBy isSpace s == words s
A variant of lines with a custom test. In particular, if there is a trailing separator it will be discarded.
linesBy (== ':') "::xyz:abc::123::" == ["","","xyz","abc","","123",""]
\s -> linesBy (== '\n') s == lines s
linesBy (== ';') "my;list;here;" == ["my","list","here"]
Splits a list into components delimited by separators, where the predicate returns True for a separator element. The resulting components do not contain the separators. Two adjacent separators result in an empty component in the output.
split (== 'a') "aabbaca" == ["","","bb","c",""]
split (== 'a') ""        == [""]
split (== ':') "::xyz:abc::123::" == ["","","xyz","abc","","123","",""]
split (== ',') "my,list,here" == ["my","list","here"]
This function takes a list, and returns all suffixes whose first item matches the predicate.
This function is similar to sections, but splits the list so no element appears in any two partitions.
Split list by groups of one or more sep.
Repeatedly splits a list and collects the results
Chop a list into segments, at separators identified by the predicate. The separator items are discarded.
Chop a list at the positions when the predicate holds. Contrary to wordsBy, consecutive separator elements will result in an empty segment in the result. O(n).
intercalate [x] (chopWhen (== x) xs) == xs
split given list of a by given single a, e.g.
>>> wordsBy (== ':') "bd:3"
["bd", "3"]
The groupWith function uses the user supplied function which projects an element out of every list element in order to first sort the input list and then to form groups by equality on these projected elements
A combination of group and sort, using a part of the value to compare on.
groupSortOn length ["test","of","sized","item"] == [["of"],["test","item"],["sized"]]
A version of group where the equality is done on some extracted value.
groupOn abs [1,-1,2] == [[1,-1], [2]]
Classify values based on the result of a given function.
> classifyOn head ["sheep", "chip", "ship", "cheap"]
[["sheep","ship"],["chip","cheap"]]
> classifyOn odd [1,2,3,4,5,6]
[[1,3,5],[2,4,6]]
(cf. classify, classifyBy)
Group values using a given field selector.
Split on elements satisfying the given predicate. Equivalent to split . dropDelims . whenElt. For example:
>>> splitWhen (<0) (BV.fromList [1,3,-4,5,7,-9,0,2])
[[1,3],[5,7],[0,2]]
Split into "words", with word boundaries indicated by the given predicate. Satisfies words === wordsBy isSpace; equivalent to split . dropBlanks . dropDelims . whenElt. For example:
>>> wordsBy (=='x') (BV.fromList "dogxxxcatxbirdxx")
["dog","cat","bird"]
Split into "lines", with line boundaries indicated by the given predicate. Satisfies lines === linesBy (=='n'); equivalent to split . dropFinalBlank . dropDelims . whenElt. For example:
>>> linesBy (=='x') (BV.fromList "dogxxxcatxbirdxx")
["dog","","","cat","bird",""]
Repeatedly evaluates the second argument until the value satisfies the given predicate, and returns a list of all values that satisfied the predicate. Discards the final one (which failed the predicate).