Antanas A.
08/06/2019, 9:08 AMval context by lazy { contextProvider() }
where contextProvider() is suspend functiondiesieben07
08/06/2019, 9:10 AMcontext
to be suspend
as well. Since suspend getters / setters aren't supported yet this is not possibleAntanas A.
08/06/2019, 9:12 AMAntanas A.
08/06/2019, 9:13 AMAntanas A.
08/06/2019, 9:14 AMAntanas A.
08/06/2019, 9:14 AMgildor
08/06/2019, 9:16 AMAntanas A.
08/06/2019, 9:16 AMAntanas A.
08/06/2019, 9:16 AMgildor
08/06/2019, 9:16 AMval context = async(start = Lazy) { contextProvider() }
Antanas A.
08/06/2019, 9:16 AMAntanas A.
08/06/2019, 9:16 AMAntanas A.
08/06/2019, 9:16 AMgildor
08/06/2019, 9:17 AMAntanas A.
08/06/2019, 9:17 AMgildor
08/06/2019, 9:17 AMAntanas A.
08/06/2019, 9:17 AMAntanas A.
08/06/2019, 9:17 AMmemo
inline fun inside kotlin sdk for thatgildor
08/06/2019, 9:18 AMgildor
08/06/2019, 9:18 AMAntanas A.
08/06/2019, 9:19 AMgildor
08/06/2019, 9:19 AMAntanas A.
08/06/2019, 9:20 AMAntanas A.
08/06/2019, 9:20 AMgildor
08/06/2019, 9:20 AMgildor
08/06/2019, 9:20 AMgildor
08/06/2019, 9:20 AMAntanas A.
08/06/2019, 9:21 AMgildor
08/06/2019, 9:21 AMAntanas A.
08/06/2019, 9:22 AMAntanas A.
08/06/2019, 9:22 AMAntanas A.
08/06/2019, 9:22 AMgildor
08/06/2019, 9:22 AMgildor
08/06/2019, 9:22 AMAntanas A.
08/06/2019, 9:22 AMAntanas A.
08/06/2019, 9:22 AMgildor
08/06/2019, 9:22 AMgildor
08/06/2019, 9:23 AMgildor
08/06/2019, 9:23 AMAntanas A.
08/06/2019, 9:23 AMgildor
08/06/2019, 9:23 AMAntanas A.
08/06/2019, 9:23 AMAntanas A.
08/06/2019, 9:24 AMAntanas A.
08/06/2019, 9:24 AMAntanas A.
08/06/2019, 9:25 AMgildor
08/06/2019, 9:26 AMAntanas A.
08/06/2019, 9:27 AMAntanas A.
08/06/2019, 9:31 AMsuspend fun <R>memoize(block: suspend () -> R): () -> R {
val Undef = object {}
var value: Any = Undef
return {
if (value === Undef) value = block()
value
}
}
gildor
08/06/2019, 9:32 AMAntanas A.
08/06/2019, 9:32 AMsuspend fun context() = memoize {
contextProvider()
}
gildor
08/06/2019, 9:32 AMAntanas A.
08/06/2019, 9:32 AMAntanas A.
08/06/2019, 9:32 AMAntanas A.
08/06/2019, 9:32 AMAntanas A.
08/06/2019, 9:32 AMgildor
08/06/2019, 9:32 AMgildor
08/06/2019, 9:33 AMreturn suspend { }
Antanas A.
08/06/2019, 9:34 AMsuspend fun <R> memoize(block: suspend () -> R): suspend () -> Any {
val Undef = object {}
var value: Any = Undef
return suspend {
if (value === Undef) value = block() as Any
value
}
}
seems this is okAntanas A.
08/06/2019, 9:34 AMgildor
08/06/2019, 9:34 AMAntanas A.
08/06/2019, 9:35 AMAntanas A.
08/06/2019, 9:35 AMgildor
08/06/2019, 9:35 AMgildor
08/06/2019, 9:35 AMgildor
08/06/2019, 9:35 AMAntanas A.
08/06/2019, 9:36 AMgildor
08/06/2019, 9:36 AMgildor
08/06/2019, 9:36 AMAntanas A.
08/06/2019, 9:37 AMsuspend fun <R> (suspend () -> R).memoize(): suspend () -> Any {
val Undef = object {}
var value: Any = Undef
return suspend {
if (value === Undef) value = this() as Any
value
}
}
and it could be extension function on any function
(maybe too much)gildor
08/06/2019, 9:37 AMgildor
08/06/2019, 9:37 AMthis() as AnyIs invalid. R may be null
Antanas A.
08/06/2019, 9:38 AMAntanas A.
08/06/2019, 9:38 AMAntanas A.
08/06/2019, 9:43 AMsuspend inline fun <R> (suspend () -> R).memoize(): suspend () -> R {
val Undef = object {}
var value: Any? = Undef
return suspend {
if (value === Undef) value = this() as Any?
value as R
}
}
and usage:
val lazyContextProvider = contextProvider.memoize()
/// ...
val context = lazyContextProvider()
Big Chungus
08/06/2019, 9:49 AMBig Chungus
08/06/2019, 9:50 AMval context by lazy { runBlocking{ contextProvider() } }
gildor
08/06/2019, 9:51 AMAny?
gildor
08/06/2019, 9:51 AMBig Chungus
08/06/2019, 9:53 AMgildor
08/06/2019, 9:55 AMgildor
08/06/2019, 10:01 AMthese implementations (Funktionale,Arrow) are not suspend friendly@Antanas A. Yes, I know, there is no way to make them suspend friendly, only by generating suspend version of them, If you use Arrow, you can create a feature requests about it
Antanas A.
08/06/2019, 10:01 AMAntanas A.
08/06/2019, 10:01 AMAntanas A.
08/06/2019, 10:02 AMDico
08/06/2019, 1:33 PMsuspend operator fun getValue(...)
is invalid?Dico
08/06/2019, 1:33 PM