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

Add a function to try things until first 'Result' #45

Open
chshersh opened this issue May 28, 2020 · 1 comment
Open

Add a function to try things until first 'Result' #45

chshersh opened this issue May 28, 2020 · 1 comment
Labels
core idea 💡 RFC, feature ideas question Further information is requested

Comments

@chshersh
Copy link
Contributor

The proposed type:

trials :: Monad m => [m a] -> (a -> m (Trial e b)) -> m (Trial e b)

What should be the name? trials tryUntil firstResult ...

@chshersh chshersh added idea 💡 RFC, feature ideas question Further information is requested core labels May 28, 2020
@chshersh
Copy link
Contributor Author

In the real use case, I have two functions:

foo :: IO (Trial e Config)
bar :: IO (Trial e Config)

I desperately want to write in a nice syntax something like this:

foo <|> bar

But Alternative instance for IO doesn't work that way... We can introduce a new operator, like, lazy monadic alternative with the following type and semantics:

<||> :: Monad m => m (Trial e a) -> m (Trial e a) -> m (Trial e a)
  • If the first Trial is Result then don't perform second action, otherwise perform second and use <|> (or <>, depending on Change Alternative instance #50) on both values.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core idea 💡 RFC, feature ideas question Further information is requested
Projects
None yet
Development

No branches or pull requests

1 participant