Hi again, I'm going to repeat a question that may ...
# arrow
m
Hi again, I'm going to repeat a question that may have got lost in my previous one. I'm looking at the docs at https://arrow-kt.io/docs/patterns/dependency_injection/#using-di-to-inject-any-object but can't get the following to work (towards the end):
Copy code
with (Option.monadError()) {
  createId("123") shouldBe Some(123)
  // ...
In the code above it,
createId
is an extension of
MonadThrow
not
MonadError
so this doesn't compile. How do I get a
monadThrow
from an
Option
to make this work?
s
You cannot construct a
MonadThrow
instance for
Option
since
Option
cannot deal with
Throwable
as an error.
p
It kinda did. MonadThrow is a MonadError where the error is Throwable, This is not possible with Option while respecting the test suite
beaten by a few seconds!
😄
😄 1
m
Thanks both. It's a shame because preceding that block it says "And as a consequence to all of this, testability and refactoring possibilities are through the roof! Many of the promises of OOP, fulfilled with simple functions and interfaces.", but I don't know how to fix the code to make this statement true, as I'm trying to learn arrow through its docs.
Is it possible to fix that test?
p
switching to Either:
Either.monadError()
Option is...nice, still doesn't have much over simple nullable types
Either retains errors, and allows you to swap the implementation with Validated and Option for some use cases
m
Thanks Paco