For a combination between maps and sets, you could...
# kotlin-inject
e
For a combination between maps and sets, you could wire something together but it would be a bit complicated
Copy code
typealias Foo1 = Foo
typealias Foo2 = Foo

@Provides @IntoSet
fun foo1ForSet1(): Foo1 = ...
@Provides @IntoSet
fun foo2ForSet1(): Foo1 = ...
@Provides @IntoSet
fun foo1ForSet2(): Foo2 = ...
@Provides @IntoSet
fun foo2ForSet2(): Foo2 = ...

@Provides @IntoMap
fun fooSet1(set: Set<Foo1>): Pair<String, Set<Foo>> = "one" to set
@Provides @IntoMap
fun fooSet2(set: Set<Foo2>): Pair<String, Set<Foo>> = "two" to set
d
I thought of that, but it does seem a bit messy... in the end I opted to make a factory class in this case. This use might be a bit too niche to be in kotlin-inject, I was just hoping it was already there 😉.
e
yeah I think it might be, not sure what the syntax would even look like
d
I wonder if there's a meaningful error in such a case... (using
@IntoMap @IntoSet
)... that's one of the problems with annotations, you can't assure the right combinations are being used and what the wrong ones might do...
e
Yeah I believe it could error out if you had both
hm, actually that could be valid in theory
Copy code
fun @Provides @IntoMap @IntoSet fun provideFoo(): Pair<String, Foo> = ...
abstract val fooMap: Map<String, Foo>
abstract val fooSet: Set<Pair<String, Foo>>
not sure if useful in practice...
d
🙃...
If already, THAT could probably be turned into a
Map<String, Set<Foo>>
... not so pressing, but if easy to implement, would make that a bit more logical...
Truth is, that if there are multiple on the same key even without the
@IntoSet
would probably throw... maybe an
@IntoMapSet
would do both?
Copy code
fun @Provides @IntoMap fun provideFoo1(): Pair<String, Foo> = "some-key" to Foo1()

fun @Provides @IntoMap fun provideFoo2(): Pair<String, Foo> = "some-key" to Foo2()
e
so actually that won't through heh, it will generate
Copy code
mapOf(provideFoo1(), provideFoo2())
and the second key would override the first