Kevin Meredith
Kevin Meredith

Reputation: 41909

Convert List of Lists into Tuple

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])

Upvotes: 0

Views: 503

Answers (1)

daniel gratzer
daniel gratzer

Reputation: 53871

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.

Upvotes: 9

Related Questions