3 ms·
I'm not familiar with swift, but in Haskell, you can't write the following: flatMap :: Either e a -> (a -> Either e b) -> Either e b flatMap x f =
by DanWaterworth 12y ago
I'm not familiar with swift, but in Haskell, you can't write the following:
flatMap :: Either e a -> (a -> Either e b) -> Either e b
flatMap x f =
case x of
Left _ -> x
Right x' -> f x'
In the case expression, you have to write `Left err -> Left err`, because `x` here has the type `Either e a`, but `Either e b` is expected.
- JSoto 12y agoYeah, this is correct. This would be wrong: func map<U>(f: T -> U) -> Result<U> { switch self { case let .Value(value): return Result<U>.Value(Box(f(value.unbox))) case let .Error(error): // self is Result<T>, but the return type must be Result<U> return self } }