Transpose function does not work

I won’t provide code both because I can’t write now and because since this is homework the best is if you can come up with the solution yourself.

However, I am going to give you an advice.
A simple solution requires two tail-recursions, one nested in the other.

The outer one should be pretty straightforward if you can come up with the internal one.

And the internal one has this signature.

def getAllHeads[A](data: List[List[A]]): Option[(List[A], List[List[A]])]

It would check if all inner lists are not empty, if so it will return all heads and tails.
Otherwise a None

I hope that helps.

1 Like