Maybe.map通过返回一对的函数

时间:2018-04-25 17:08:59

标签: elm

我有一个带有Type签名的函数

a -> b -> (a, b)

我有

Maybe a

如何映射这样的功能以便我可以

(a->b->(a,b)) -> Maybe a -> (Maybe a, b)

1 个答案:

答案 0 :(得分:0)

您需要稍微更改功能定义

g : (a -> b -> (a,b)) -> Maybe a -> b -> (Maybe a, b)
g f ma b =
  case ma of
    Nothing -> (Nothing, b)
    Just a -> 
      let
        r = f a b
      in
        (Just (first r), second r)