DEV Community

Discussion on: Pack the same elements into a list inside a list.

antonrich profile image
Anton Author

For now I have this. Can you guess what's wrong with this code?

pack : List a -> List (List a)
pack list =
    List.foldr pusher [] list

pusher : a -> List b -> List (List b)
pusher y ys =
    if List.isEmpty ys then
        y :: ys
        if y == List.head <| List.head ys then
            y :: List.head ys
            [y] :: ys