Is there a way to get a compile-time warning or er...
# arrow
a
Is there a way to get a compile-time warning or error when an
Either<E, A>
is not used? In particular, this would be great in an
either { … }
block when calling IO functions that return
Either<Error, Unit>
to prevent forgetting to call
bind()
on the result to propagate the error.
m
that indeed would be very helpful
s
I'd love to have something like this but not sure what the best way to do this would be. If compiler plugins (FIR) because stably available, we could include this in an Arrow plugin. Otherwise, we would have to build something for Detekt or KtLint. Which afaik is not super hard, but requires the users to opt-in to those tools.
e
I think this issue would make it easy to solve.. https://youtrack.jetbrains.com/issue/KT-12719
m
yeah, something like rust already has: https://doc.rust-lang.org/reference/attributes/diagnostics.html#the-must_use-attribute /edit: sorry, wrong link.
e
Also includes a link to a detekt rule you could use as an intermediary solution
a
Yes, I was thinking of the
#[must_use]
attribute in Rust. It's great to see that there are discussions around something similar.
👍 1
s
Very interesting indeed, but seems more like a user-side feature than something we can solve in Arrow. I'm going to apply this in one of my toy projects since I'm already using Detekt in most projects.
e
@simon.vergauwen given IntelliJ/compiler support for the annotation, it could be solved by adding the annotation in appropriate places 🙂