I was wondering how could I write a function in Haskell that interleaves a list of lists into a single lists, for example, if I had a function called
interleav
we could do what you want
testList = [[1,2,3],[4,5,6],[7,8]]
interleave l = foldr' (concat [map (\x -> f x idx) l | idx <- [0..]])
where
f x n = if (length(x)<=n) then Nothing else Just (x !! n)
foldr' (x:xs) = case x of
Nothing -> []
Just a -> (:) a (foldr' xs)
As required interleave [[1,2,3] [4,5,6] [7,8]] => [1, 4, 7, 2, 5, 8, 3, 6]