https://kotlinlang.org logo
#announcements
Title
# announcements
m

mp

07/08/2019, 6:11 PM
Let's not get wrapped up in the threadlocal. How about this. I have a consuemr
(T) -> Unit
and a producer
() -> T
. I want to store pairs of those, but with a different
T
for each pair.
d

Dico

07/08/2019, 6:12 PM
Put them in individual properties
m

mp

07/08/2019, 6:12 PM
No, I want a collection.
d

Dico

07/08/2019, 6:13 PM
The elements retrieved from a collection cannot have a different type at compile time so you're going to need a
Collection<MyPair<*>>
Copy code
class MyPair<T>(collector, producer) {
    fun run() = collector(producer())
}
Copy code
for (pair in pairs) pair.run()
m

mp

07/08/2019, 6:23 PM
yeah, I ended up going with something similar
thanks for teddy-bearing 🙂