>>> interact (\str -> str ++ str) > hi :) hi :) > ^D hi :)
>>> interact (const ":D") :D
>>> interact (show . words) > hello world! > I hope you have a great day > ^D ["hello","world!","I","hope","you","have","a","great","day"]
>>> 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]
>>> [1,2,3,4] `intersect` [2,4,6,8] [2,4]If equal elements are present in both lists, an element from the first list will be used, and all duplicates from the second list quashed:
>>> import Data.Semigroup >>> intersect [Arg () "dog"] [Arg () "cow", Arg () "cat"] [Arg () "dog"]However if the first list contains duplicates, so will the result.
>>> "coot" `intersect` "heron" "oo" >>> "heron" `intersect` "coot" "o"If the second list is infinite, intersect either hangs or returns its first argument in full. Otherwise if the first list is infinite, intersect might be productive:
>>> intersect [100..] [0..] [100,101,102,103... >>> intersect [0] [1..] * Hangs forever * >>> intersect [1..] [0] * Hangs forever * >>> intersect (cycle [1..3]) [2] [2,2,2,2...
>>> take 1 (intersperse undefined ('a' : undefined)) "a"
>>> take 2 (intersperse ',' ('a' : undefined)) "a*** Exception: Prelude.undefined
>>> intersperse ',' "abcde" "a,b,c,d,e"
>>> intersperse 1 [3, 4, 5] [3,1,4,1,5]
>>> intercalate1 ", " $ "hello" :| ["how", "are", "you"] "hello, how, are, you"
>>> intercalate1 ", " $ "hello" :| [] "hello"
>>> intercalate1 mempty $ "I" :| ["Am", "Fine", "You?"] "IAmFineYou?"
intersperse 0 (1 :| [2,3]) == 1 :| [0,2,0,3]
>>> T.intercalate "NI!" ["We", "seek", "the", "Holy", "Grail"] "WeNI!seekNI!theNI!HolyNI!Grail"
>>> T.intersperse '.' "SHIELD" "S.H.I.E.L.D"Performs replacement on invalid scalar values.
intercalate s = concat . intersperse s
unstream . intersperse c . stream = intersperse c