-
Notifications
You must be signed in to change notification settings - Fork 21
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
Allow queries to be eagerly constructed #488
Conversation
/** | ||
* Eagerly constructs a query that succeeds with the specified value. | ||
*/ | ||
def succeedNow[A](value: A): ZQuery[Any, Nothing, A] = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we ok with having this part of the public API? I know historically the core has made *Now
stuff package private to avoid footguns.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Personally I think it's okay. Most (if not all) other frameworks, including Scala's Future (which I know isn't the best example because it's not referentially transparent) expose methods for eagerly constructing monads. I think in ZIO having the *Now
methods makes less sense because it has Exit
. In ZQuery users don't really have that option.
b486cfc
An issue with ZQuery that makes it hard to optimize in libraries like Caliban is that it doesn't provide any means to eagerly construct queries who's values can be extracted without executing the queries via the ZIO runtime.
Let's take this as an example:
In the example above, the first 2 branches do not require us to run the ZQuery in order to evaluate it as the outcome is already known.
This PR exposes
xNow
variants of different methods that allow users to eagerly construct ZQueries. Libraries (like Caliban) can then check if a ZQuery is eagerly constructed via theasExitMaybe
andasExitOrElse
methods and extract the value/failure from it without the need of running the ZQuery and providing a Cache to it.