one thing I've always liked the idea of is diction...
# tornadofx
g
one thing I've always liked the idea of is dictionaries keyed by type, that return typed values. Coroutines implemented this with coroutine scope, where you can write
coroutineScope[Job]
and the static type of the return expression is
Job
. Similarly the static type of
coroutineScope[Dispatcher]
is
Dispatcher
. I'm looking at
Node.properties: Map<Object, Object>
and wishing it was something similar to
CoroutineContext
. Ideally I could write something like
myNode.typedProps[ImportantListener]...
Has anybody implemented this?
r
That works with coroutines because the scope getter only accepts a specific interface (or maybe sealed class, I don't remember for sure) that the companions of all the valid types implement. The closest you could get to what you're going for would be to pass in a class (using an inline function for pretty syntax), and probably wrap the class in a private wrapper to avoid a duplicate key issue.