We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
The MonadThrow class might look something like this:
MonadThrow
interface MonadThrow extends Monad { function throwM($errObj); }
This will make it easier to make methods generic in their return monads. For example, one could write a database-querying method like so:
class MyRepository { function getEntityById(string $id, $monadThrow = new MaybeMonad()) { $dbEntity = ... // query the database return is_null($dbEntity) ? $monadThrow->throwM("Entity with ID: " . $id . " could not be found.") : $monadThrow->pure($dbEntity); } }
If the caller desires the return type to be Maybe, they could simply call it like this:
Maybe
$maybeEntity = $repository->getEntityById("123456");
But if, say, an Attempt is desired, then they could call it like this:
Attempt
$attemptEntity = $repository->getEntityById("123456", new AttemptMonad());
This presumes, of course, that both MaybeMonad and AttemptMonad have implemented the MonadThrow interface.
MaybeMonad
AttemptMonad
The text was updated successfully, but these errors were encountered:
No branches or pull requests
The
MonadThrow
class might look something like this:This will make it easier to make methods generic in their return monads. For example, one could write a database-querying method like so:
If the caller desires the return type to be
Maybe
, they could simply call it like this:But if, say, an
Attempt
is desired, then they could call it like this:This presumes, of course, that both
MaybeMonad
andAttemptMonad
have implemented theMonadThrow
interface.The text was updated successfully, but these errors were encountered: