Pregunta

How can I convert a list of lists [[a]] into a tuple ([a], [a])?

Example:

input: [[1], [2,3,4]]

output: ([1], [2,3,4])

¿Fue útil?

Solución

How about pattern matching?

convert :: [[a]] -> Maybe ([a], [a])
convert [x, y] = Just (x, y)
convert _      = Nothing

The Maybe is just to handle the case where we don't have exactly two elements in our list.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top