我有一个包含纬度/经度对的字符串:
"50.0814253N, 14.4876106E"
我想将其解析为Maybe (Float, Float)
。我可以很容易地到达[Just 50.0814253, Just 14.4876106]
或类似的东西,但获得最终的Maybe (Float, Float)
非常混乱。有从List (Maybe Float)
到Maybe (Float, Float)
的好方法吗?
答案 0 :(得分:8)
如果您已经[Just 50.0814253, Just 14.4876106]
并想要Maybe (Float, Float)
,则可以使用与case ... of
的简单模式匹配:
let list = [Just 50.0814253, Just 14.4876106]
in
case list of
[Just a, Just b] ->
Just (a, b)
_ ->
None