I\'m trying to write a haskell function that takes in two lists of integers and generates a list with elements that have been taken alternatingly from the two lists.
I
A solution without using concat
or explicit recursion:
blend l = foldr($)[] . zipWith(.) (map(:)l) . map(:)
We can make also make this point-free
blend' = (foldr($)[].) . (.map(:)) . zipWith(.) . map(:)
\[1,2,3] [4,5,6] -> [1:, 2:, 3:] [4:, 5:, 6:]
then we zip this together with function composition
-> [(1:).(4:), (2:).(5:), (3:).(6:)]
and finally fold the application of all these compositions from the right to the empty list
-> (1:).(4:) $ (2:).(5:) $ (3:).(6:) $ [] = 1:4:2:5:3:6:[] = [1,4,2,5,3,6]