intercalate package:streamly-core

intersperse followed by unfold and concat.
>>> intercalate u a = Stream.unfoldMany u . Stream.intersperse a

>>> intersperse = Stream.intercalate Unfold.identity

>>> unwords = Stream.intercalate Unfold.fromList " "
>>> input = Stream.fromList ["abc", "def", "ghi"]

>>> Stream.fold Fold.toList $ Stream.intercalate Unfold.fromList " " input
"abc def ghi"
intersperseMSuffix followed by unfold and concat.
>>> intercalateSuffix u a = Stream.unfoldMany u . Stream.intersperseMSuffix a

>>> intersperseMSuffix = Stream.intercalateSuffix Unfold.identity

>>> unlines = Stream.intercalateSuffix Unfold.fromList "\n"
>>> input = Stream.fromList ["abc", "def", "ghi"]

>>> Stream.fold Fold.toList $ Stream.intercalateSuffix Unfold.fromList "\n" input
"abc\ndef\nghi\n"
Insert the given array after each array and flatten.
>>> intercalateSuffix = Stream.intercalateSuffix Array.reader
Apply two parsers alternately to an input stream. The input stream is considered an interleaving of two patterns. The two parsers represent the two patterns. Parsing starts at the first parser and stops at the first parser. It can be used to parse a infix style pattern e.g. p1 p2 p1 . Empty input or single parse of the first parser is accepted.
>>> p1 = Parser.takeWhile1 (not . (== '+')) Fold.toList

>>> p2 = Parser.satisfy (== '+')

>>> p = Parser.deintercalate p1 p2 Fold.toList

>>> Stream.parse p $ Stream.fromList ""
Right []

>>> Stream.parse p $ Stream.fromList "1"
Right [Left "1"]

>>> Stream.parse p $ Stream.fromList "1+"
Right [Left "1"]

>>> Stream.parse p $ Stream.fromList "1+2+3"
Right [Left "1",Right '+',Left "2",Right '+',Left "3"]
Apply two parsers alternately to an input stream. The input stream is considered an interleaving of two patterns. The two parsers represent the two patterns. Parsing starts at the first parser and stops at the first parser. It can be used to parse a infix style pattern e.g. p1 p2 p1 . Empty input or single parse of the first parser is accepted.
>>> p1 = Parser.takeWhile1 (not . (== '+')) Fold.toList

>>> p2 = Parser.satisfy (== '+')

>>> p = Parser.deintercalate1 p1 p2 Fold.toList

>>> Stream.parse p $ Stream.fromList ""
Left (ParseError "takeWhile1: end of input")

>>> Stream.parse p $ Stream.fromList "1"
Right [Left "1"]

>>> Stream.parse p $ Stream.fromList "1+"
Right [Left "1"]

>>> Stream.parse p $ Stream.fromList "1+2+3"
Right [Left "1",Right '+',Left "2",Right '+',Left "3"]
Like deintercalate but the entire input must satisfy the pattern otherwise the parser fails. This is many times faster than deintercalate.
>>> p1 = Parser.takeWhile1 (not . (== '+')) Fold.toList

>>> p2 = Parser.satisfy (== '+')

>>> p = Parser.deintercalateAll p1 p2 Fold.toList

>>> Stream.parse p $ Stream.fromList ""
Right []

>>> Stream.parse p $ Stream.fromList "1"
Right [Left "1"]

>>> Stream.parse p $ Stream.fromList "1+"
Left (ParseError "takeWhile1: end of input")

>>> Stream.parse p $ Stream.fromList "1+2+3"
Right [Left "1",Right '+',Left "2",Right '+',Left "3"]
interleaveFst followed by unfold and concat. Pre-release
interleaveFstSuffix followed by unfold and concat. Pre-release