https://kotlinlang.org logo
#coroutines
Title
# coroutines
d

Dias

12/17/2018, 10:31 AM
I am reading coroutines keep and there is a line that doesn't make sense to me:
It is a mix between a set and a map. Its elements have keys like in a map, but its keys are directly associated with elements, more like in a set.
But sets don't have keys, do they? And maps have their keys directly associated with values? Am I reading it wrong?
💯 2
m

Martin Devillers

12/17/2018, 10:48 AM
Shameless self-promotion, but I think this could answer your question: https://proandroiddev.com/demystifying-coroutinecontext-1ce5b68407ad
d

Dias

12/17/2018, 10:59 AM
which part of it?
It is an indexed set of Element instances. An indexed set is a mix between a set and a map. Every element in this set has a unique Key. Keys are compared by reference.
?
m

Martin Devillers

12/17/2018, 11:00 AM
Yes, the
Structure
section
d

Dias

12/17/2018, 11:01 AM
yeah I understand that context is just a map with unique keys, but the description that confuses me is not exactly that
m

Martin Devillers

12/17/2018, 11:02 AM
Yes I’m not sure that I really understand the comparison between a
CoroutineContext
and a set as well, it’s more like a map, I agree.
The comparison with a set stems from the fact that the unicity on the type of values is itself ensured.
Basically, in a true map, you can have any values you want. You can, for example, have the same value mapped by different keys. That’s not possible in this case.
The key is imposed by the type of the value
But I’m not sure that this analogy of a “Set” really clarifies things
d

Dias

12/17/2018, 11:35 AM
yeah what you are saying makes sense
I wonder if it's what they meant as well
3 Views