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