Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

expected: map([...] (...) -> expected<...> { ... }) produces expected<expected> #41

Open
ArsenArsen opened this issue Aug 31, 2022 · 2 comments

Comments

@ArsenArsen
Copy link
Member

ArsenArsen commented Aug 31, 2022

While this behavior is probably fine, it would be desirable to be able to chain expecteds for monadic operations.

For an example of such see Haskell's Either

-- Module      :  Data.Either
-- Copyright   :  (c) The University of Glasgow 2001
-- License     :  BSD-style (see the file libraries/base/LICENSE)

-- | @since 4.4.0.0
instance Monad (Either e) where
    Left  l >>= _ = Left l
    Right r >>= k = k r

In essence, this means that >>= propagates error and does not evaluate k (type: a -> Either e b) unless the Either is a Right (success case)

EDIT: similarly, there's no way to implicitly convert to a different expected result of same error (one would have to do if (!e) { {co_}return e.error(); })

@avdgrinten
Copy link
Member

This functionality is useful, of course, but it'd rather have it in a separate function (other than map()) such that the function that is passed in can always be assumed to return a frg::expected.

@ArsenArsen
Copy link
Member Author

Agreed, that's what I meant by "While this behavior is probably fine, it would be desirable to be able to chain expecteds for monadic operations". A sensible name might be then or chain

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants