Interleave List of Lists in Haskell

后端 未结 4 1977
借酒劲吻你
借酒劲吻你 2020-12-16 23:57

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

4条回答
  •  轮回少年
    2020-12-17 00:19

    Simple recursive version:

    inter :: [[a]] -> [a]
    inter [] = []
    inter xs = inter2 (filter (\x -> not (null x)) xs)
       where inter2 xs = map head xs ++ inter (map tail xs)
    

    Now, about foldr...

提交回复
热议问题