I am reading coroutines keep and there is a line t...
# coroutines
d
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
Shameless self-promotion, but I think this could answer your question: https://proandroiddev.com/demystifying-coroutinecontext-1ce5b68407ad
d
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
Yes, the
Structure
section
d
yeah I understand that context is just a map with unique keys, but the description that confuses me is not exactly that
m
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
yeah what you are saying makes sense
I wonder if it's what they meant as well