dave08
05/14/2024, 10:26 AMEither<ErrorType, Unit>
as the return type? (When context receivers land, it'll probably be better, but for now...). Maybe an Option<ErrorType>
makes more sense?simon.vergauwen
05/14/2024, 12:12 PMEither<ErrorType, Unit>
is very common for this, and is whysimon.vergauwen
05/14/2024, 12:13 PMOption<ErrorType>
is also used, although more uncommon sometimes it's the preferred API. Typically that is the case for optional error handling.
Raise would of course make most sense, since it can never be forgotten to be bound.dave08
05/14/2024, 1:58 PMoptional error handlingIsn't that my case?
dave08
05/14/2024, 1:59 PMEither<ErrorType, Unit>
would be better to represent whether there was an error or not... isn't that really what Option would be representing here?simon.vergauwen
05/14/2024, 2:04 PMdave08
05/14/2024, 3:02 PMval someFun = effect {...}
would be better, but then you could forget the ()
😂dave08
05/14/2024, 3:03 PMsimon.vergauwen
05/14/2024, 4:12 PMOption<ErrorType>
is a good option, if you only want to be able to "inspect" the error, but don't want it to short-circuit your logic. Which doesn't seem what you want.
What I would currently do, not sure if possible, is use Raise
as an extension receiver. It's not always possible, though but if possible that's what I do now. (Typically it's a private function).dave08
05/15/2024, 9:20 AMsimon.vergauwen
05/15/2024, 9:55 AMtailrec
which is not possible with Either
in the return type 😉
It's just simple private class method, so it's not exposed to the rest of the codebase, so I think that's perfect!
TBH, I might still do this if applicable when context receivers arrive. Prefer simpler solution where possible applies here a bit I guessdave08
05/15/2024, 9:58 AM