解析纬度和范围来自字符串的经度对

时间:2018-03-24 20:22:22

标签: elm

我有一个包含纬度/经度对的字符串:

"50.0814253N, 14.4876106E"

我想将其解析为Maybe (Float, Float)。我可以很容易地到达[Just 50.0814253, Just 14.4876106]或类似的东西,但获得最终的Maybe (Float, Float)非常混乱。有从List (Maybe Float)Maybe (Float, Float)的好方法吗?

1 个答案:

答案 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