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

How to deal with Tasks<Monad<T>> types when you have multiple in a pipeline. #761

Open
FreeApophis opened this issue Nov 15, 2023 · 0 comments

Comments

@FreeApophis
Copy link
Member

Example:

We have two functions which are asnyc because they get data asynchronosly, the second function needs the value of the first, a typcal sitation for SelectMany:

Task<Option<int>> GetId() => ...
Task<Option<int>> GetObjectById(int) => ...

// type bingo!
Option<int> y = (await (await GetId()).Select(x => f(x))).SelectMany(Identity);

If the functions would not be async we could easily use the typical SelectMany pipelines, ideally we would have something like this:

GetId().SelectMany(GetObjectById)

or

from id in GetId()
from o in GetObjectById(id)
select o;
  • The same applies to the other Monads (Either, Reader)
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

1 participant