>>> intercalateEndBy u1 s1 u2 s2 = Stream.concat $ Stream.interleaveEndBy (fmap (Stream.unfold u1) s1) (fmap (Stream.unfold u2) s2)Pre-release
>>> intercalateSepBy u1 s1 u2 s2 = Stream.concat $ Stream.interleaveSepBy (fmap (Stream.unfold u1) s1) (fmap (Stream.unfold u2) s2)If the separator stream consists of nil streams then it becomes equivalent to unfoldEach:
>>> unfoldEach = Stream.intercalateSepBy (Unfold.nilM (const (return ()))) (Stream.repeat ())Pre-release
>>> 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"]See also chainl1.
>>> p1 = Parser.takeWhile1 (not . (== '+')) Fold.toList >>> p2 = Parser.satisfy (== '+') >>> p = Parser.deintercalate1 p1 p2 Fold.toList >>> Stream.parsePos p $ Stream.fromList "" Left (ParseErrorPos 0 "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"]
>>> 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.parsePos p $ Stream.fromList "1+" Left (ParseErrorPos 2 "takeWhile1: end of input") >>> Stream.parse p $ Stream.fromList "1+2+3" Right [Left "1",Right '+',Left "2",Right '+',Left "3"]See also chainl1.