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
split "," "foo,bar,,baz," -> ["foo", "bar", "", "baz", ""]
split "ba" ",foo,bar,,baz," -> [",foo,","r,,","z,"]
\(QC.NonEmpty xs) (QC.NonEmpty ys) -> PolyCore.tensorProduct xs ys == List.transpose (PolyCore.tensorProduct ys (intPoly xs))
>>> 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) === idsplitOn 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.)
>>> splitOneOf (BV.fromList ";.,") (BV.fromList "foo,bar;baz.glurk") ["foo","bar","baz","glurk"]
>>> endBy (BV.fromList ";") (BV.fromList "foo;bar;baz;") ["foo","bar","baz"]Note also that the lines function from Data.List is equivalent to endBy "n".
>>> endByOneOf (BV.fromList ";,") (BV.fromList "foo;bar,baz;") ["foo","bar","baz"]