phldavies
02/18/2025, 7:53 PMputOrRaise
(and similar) helpers that take a payload parameter (implicitly receiving a la fun <reified B: Any> Route.put(String, (B) -> Unit): Route
I'm hitting an overload ambiguity between the following:
inline fun <reified B : Any, reified R> Route.putOrRaise(
path: String,
crossinline body: suspend RaiseRoutingContext.(B) -> R,
): Route
and
public inline fun <reified R> Route.putOrRaise(
path: String,
crossinline body: suspend RaiseRoutingContext.() -> R,
): Route
when attempting to use the non-receiving form, i.e. putOrRaise("/path") { "my result" }
.
You could disambiguate either with putOrRaise("/path") { -> "my result" }
or putOrRaise<_>("/path") { "my result" }
but neither are intuitive or ergonomic to write.
The only reasonable alternative I can think of is to rename the "receiving" helpers like putOrRaiseReceiving
or putReceivingOrRaise
or such, but again, not very ergonomic.
Any other thoughts or ideas? Do we even need/want to include a "receiving" form of these, given a consumer could just use put<B>("/path") { respondOrRaise { "my result " }
or putOrRaise("/path") { val it = receiveOrRaise<T>() }
as needed?phldavies
02/18/2025, 7:57 PMput
equivalent pair (fun Route.put(String, RoutingContext.() -> Unit)
vs fun <R> Route.put(String, RoutingContext.(R) -> Unit)
) is enough to disambiguate - unfortunately both putOrRaise
overloads need type args to reify either the input or output types.Youssef Shoaib [MOD]
02/18/2025, 9:16 PMinline fun <reified B : Any, reified R> Route.putOrRaise(
path: String,
unit: Unit = Unit,
crossinline body: suspend RaiseRoutingContext.(B) -> R,
): Route
I think this'll disambiguate them, and it'll also get chosen for putOrRaise<T, _> { ... }
and putOrRaise { t: T -> ... }
phldavies
02/18/2025, 9:35 PMmarker: Nothing? = null
earlier and Unit just now - no luckphldavies
02/18/2025, 11:07 PMYoussef Shoaib [MOD]
02/18/2025, 11:12 PMcrossinline
anyways, so we don't lose out on much by doing that.
I'll keep this trick in my back pocket!phldavies
02/18/2025, 11:24 PMAlejandro Serrano.Mena
02/19/2025, 8:47 AMputOrRaise("/path") { "my result" }
even for the first overloadphldavies
02/19/2025, 8:51 AMphldavies
02/19/2025, 9:53 AMput<B>("/path") { respondOrRaise { "my result " }
or putOrRaise("/path") { val it = receiveOrRaise<T>() }
as needed?
It's why I raised this point though - I've personally never used the "pre-receiving" versions, always preferring to call.receive
as/when needed. We can always add them later. That said, they're there now.