DEV Community

loading...

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

Collapse
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
    else
        if y == List.head <| List.head ys then
            y :: List.head ys
        else
            [y] :: ys