Hey, all. What are your naming conventions for sus...
# naming
p
Hey, all. What are your naming conventions for suspending variations of non-suspending functions? •
doThing()
doThingAsync()
doThingSuspending()
doThingSuspended()
◦ etc?
e
ideally, •
fun doThingBlocking()
suspend fun doThing()
if both need to exist, otherwise only the latter
p
My specific use case is a
fold
function where the closure invokes a suspending function, like so:
Copy code
fun parse(input: String): Result<Parsed, Error>

parse(inputString).fold(
    { value -> suspendingNetworkCall(value) },
    { error -> suspendingLoggingCall(error) }
)
So I have
fold
and
foldSuspended
at the moment. 😬
e
if it's a higher-order function, it may make sense to make it
inline
, and then it works the same regardless of whether the lambdas suspend or not
p
Interesting, because that's what I have and though I though it would work, it's not. I'll fiddle with the modifiers and report back.
Ah, it's because I was using
crossinline
for the HOFs
e
and if it really needs to be non-inline, overloading should work fine, e.g.
Copy code
fun Result<Parsed, Error>.fold(
    onSuccess: (Parsed) -> R,
    onError: (Error) -> R,
)
suspend fun Result<Parsed, Error>.fold(
    onSuccess: suspend (Parsed) -> R,
    onError: suspend (Error) -> R,
)
p
Removing
crossinline
fixed my issue. Thanks.