質問

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

役に立ちましたか?

解決

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.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top