Nick Kleban
03/06/2024, 8:51 AMYoussef Shoaib [MOD]
03/06/2024, 8:56 AMRaise<ErrorType>.myFun(): Unit
Nick Kleban
03/06/2024, 8:59 AMeither{ }
in a function that returns Either<Error, Unit>, do I need to bind Unit or something?simon.vergauwen
03/06/2024, 8:59 AMRaise
directly, you can also use Either<ErrorType, Unit>
but then you need to make sure to always call bind
. There is a detekt plugin to check that.simon.vergauwen
03/06/2024, 9:00 AMbind
on Either<Error, Unit>
, otherwise you'd swallow/ignore to error.
Or, recover using getOrElse
, etc.simon.vergauwen
03/06/2024, 9:01 AMRaise<ErrorType>.myFun(): Unit
is safest, you can call it inside either<ErrorType, Unit> { myFun() }
but you don't need to call bind
.
Raise<ErrorType>
gives you the exact same API as you get inside either<ErrorType, Unit> { }
, but Either
is perfectly valid if that's what you're using everywhere in your project ☺️ If it's a private
function you could still consider Raise
IMO.Nick Kleban
03/06/2024, 9:03 AM