I'm just learning Haskell and I would like to make a "shuffle" function that shuffles together two lists, alternating until one runs out. So, shuffle "abc" "defgh"
would return "adbecfgh"
. Or shuffle "abc" ""
returns "abc"
.
So far I have:
shuffle xs ys = concatMap (\(x,y) -> [x,y]) (zip xs ys)
The problem is that it's only shuffling the lists for the length of the shortest list and not including the rest of the longer list. So shuffle "abc" "defgh"
returns "adbecf"
rather than "adbecfgh"
.
Can anyone help me find a better approach to this?