snowe
04/29/2020, 4:40 AMprivate suspend fun DeepRecursiveScope<Any?, Unit>.ppAny(obj: Any?) {
DeepRecursiveFunction<Any?, Unit> { obj ->
ppObj(obj)
}
}
private suspend fun DeepRecursiveScope<Any?, Unit>.ppObj(obj: Any) {
ppAny(obj)
}
I need to declare both as suspend and both as extension functions in order for them to be callable from within the DeepRecursiveScope. But ppAny is not callable from within ppObj, with the error
[NON_LOCAL_SUSPENSION_POINT] Suspension functions can be called only within coroutine body
Now, I understand the issue (I think), in that I need to be calling from within a context with, with(this@DeepRecursiveScopeImpl), but I do not have access to DeepRecursiveScopeImpl. Can I use another scope for this? If not, how can I get access to this scope to call my method with? Am I doing stuff completely wrong here???elizarov
04/29/2020, 7:15 AMsnowe
04/29/2020, 5:49 PMppAny calls different methods at this spot
https://github.com/snowe2010/pretty-print/blob/master/src/main/kotlin/com/tylerthrailkill/helpers/prettyprint/PrettyPrint.kt#L91-L96
and then those methods call back to ppAny like so
https://github.com/snowe2010/pretty-print/blob/master/src/main/kotlin/com/tylerthrailkill/helpers/prettyprint/PrettyPrint.kt#L139
But if I switch to the DeepRecursiveFunction, I cannot call those methods. I have to add them as extension methods on DeepRecursiveFunction. If I do that, then I cannot call callRecursive because the scope is not correct.elizarov
04/29/2020, 6:44 PMval first = DeepRecursiveFunction<A,B> { a -> .... }
suspend fun DeepRecursiveScope<*, *>.second(a: A): B { ... }
You need to at least one of the first kind to call it from the outside of your recursive computation via first(a) . Now inside any of those functions you call the first one via first.callRecursive(a) and the second one via second(a). That's it.elizarov
04/29/2020, 6:48 PMsnowe
04/29/2020, 7:18 PMsnowe
04/29/2020, 9:51 PMsnowe
05/01/2020, 3:37 PMelizarov
05/01/2020, 10:03 PMsnowe
05/02/2020, 5:46 AM