dave08
03/13/2023, 4:58 PMeffect { }
block processing the request:
val formParameters =
catch({ call.receiveParameters() }) { e -> raise(GenericRequestFailure(e.message ?: "")) }
but I can't since I don't have a Raise<> context (and I need the ApplicationCall as the receiver), do I just have to create another effect { } block for it and then use bind()
or is there a better way? It seems like Either.catch...
is deprecated... (and doesn't have a raise function?)private fun ApplicationCall.getFormParameters() = effect { catch({ receiveParameters() }) { e -> raise(GenericRequestFailure(e.message ?: "")) } }
phldavies
03/13/2023, 5:31 PMgetFormParameters
to return an Either
, is the outer effect{}
necessary?dave08
03/14/2023, 2:49 AMsimon.vergauwen
03/14/2023, 7:54 AMEither.catch isn't deprecated?No,
Either
is not deprecated and neither is Either.catch
some redundant variations of catch
are being deprecated in favor of the composition of their smaller parts.
The catch
function you show in your example is available on `alpha`:
private fun ApplicationCall.getFormParameters() = effect { catch({ receiveParameters() }) { e -> raise(GenericRequestFailure(e.message ?: "")) } }
You can do the same with Either.catch
private fun ApplicationCall.getFormParameters() = Either.catch { receiveParameters() }.mapLeft { e -> GenericRequestFailure(e.message ?: "") }
Or in DSL form:
private fun ApplicationCall.getFormParameters() = either { catch({ receiveParameters() }) { e -> raise(GenericRequestFailure(e.message ?: "")) } }
dave08
03/14/2023, 2:55 PMsimon.vergauwen
03/14/2023, 2:57 PMEffect
is not a type anymore, so it can also not have a companion
š
So there is not a clear place to define Effect.catch
.dave08
03/14/2023, 2:59 PMsimon.vergauwen
03/14/2023, 3:05 PMContinuation
lambdas are optimised by the compiler and hotspot should optimise it as well but that contains a lot of should and also heavily depends on the rest of the codebase and usage. (i.e. hotspot optimises based on what is actually happening at runtime).
IMO you should do what makes most sense for you, your codebase and team and not worry about these super tiny micro-optimisations unless maybe if you're building a framework or low-level library.phldavies
03/14/2023, 3:20 PM