>>> take 5 (intercalate undefined ("Lorem" : undefined)) "Lorem"
>>> take 6 (intercalate ", " ("Lorem" : undefined)) "Lorem*** Exception: Prelude.undefined
>>> intercalate ", " ["Lorem", "ipsum", "dolor"] "Lorem, ipsum, dolor"
>>> intercalate [0, 1] [[2, 3], [4, 5, 6], []] [2,3,0,1,4,5,6,0,1]
>>> intercalate [1, 2, 3] [[], []] [1,2,3]
>>> T.intercalate "NI!" ["We", "seek", "the", "Holy", "Grail"] "WeNI!seekNI!theNI!HolyNI!Grail"
intercalate s = concat . intersperse s
>>> intercalate ", " ["Lorem", "ipsum", "dolor"] "Lorem, ipsum, dolor"
>>> intercalate ", " ["Lorem", "ipsum", "dolor"] "Lorem, ipsum, dolor"intercalate has the following laziness properties:
>>> take 5 (intercalate undefined ("Lorem" : undefined)) "Lorem" >>> take 6 (intercalate ", " ("Lorem" : undefined)) "Lorem*** Exception: Prelude.undefined
intercalate unf a str = unfoldMany unf $ intersperse a str intersperse = intercalate (Unfold.function id) unwords = intercalate Unfold.fromList " "
>>> Stream.toList $ Stream.intercalate Unfold.fromList " " $ Stream.fromList ["abc", "def", "ghi"] "abc def ghi"
intercalate = mconcat .: intersperse
>>> intercalate ", " ["a", "b", "c"] "a, b, c"
>>> intercalate ", " ["a"] "a"
>>> intercalate ", " [] ""
>>> 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"