Is there a way to prevent a suspend lambda from being passed to an inline function?
Consider example from the library:
public inline fun <K, V> MutableMap<K, V>.getOrPut(key: K, defaultValue: () -> V): V {
val value = get(key)
return if (value == null) {
val answer = defaultValue()
put(key, answer)
answer
} else {
value
}
}
The problem with this is it can create many bugs — if lambda is suspending. I am creating a similar function and would like to prevent the caller from passing a suspending lambda. Is there a way to get a compile-time error?
UPDATE: Looks like crossinline
will do the trick?
Thanks!