dave08
10/15/2024, 11:11 AMCollection<I>
(not reified) with a spread operator to a vararg function? It seems like toTypedArray() won't work without reified...Youssef Shoaib [MOD]
10/15/2024, 11:28 AMAny?
? if so, I think you can simply upcast your Collection
to Collection<Any?>
and then do toTypedArray()
dave08
10/15/2024, 11:30 AMRedisFuture<Long> del(K... keys);
dave08
10/15/2024, 11:31 AMoverride suspend fun expire(ids: Collection<I>)
dave08
10/15/2024, 11:31 AMYoussef Shoaib [MOD]
10/15/2024, 11:33 AMAny?
should work thenphldavies
10/15/2024, 11:34 AMfun <T> del(vararg values: T) {
values.forEach {
println("deleting: $it")
}
}
fun <T> expire(ids: Collection<T>) {
del(*ids.toTypedArray<Any?>())
}
fun main() {
expire(listOf("hello", "world"))
}
dave08
10/15/2024, 11:37 AMphldavies
10/15/2024, 11:38 AMK
is bound by the Lettuce interface and cannot be lifted to Any?.dave08
10/15/2024, 11:40 AMdave08
10/15/2024, 11:41 AMdave08
10/15/2024, 11:41 AMphldavies
10/15/2024, 11:41 AM*(ids.toTypedArray<Any?>() as Array<I>)
assuming you can ensure that I == Kphldavies
10/15/2024, 11:42 AMids.toTypedArray<Any?>()
will only contain `I`s - so you can safely cast it.dave08
10/15/2024, 11:43 AMoverride suspend fun expire(ids: Collection<I>) {
connection.async().del(*(ids.toTypedArray<Any?>() as Array<I>)).await()
}
phldavies
10/15/2024, 11:44 AMK
type-arg is your I
from that context then the del
call is fine (the array casting is fine by way of your signature)dave08
10/15/2024, 11:44 AMval connection: StatefulRedisConnection<I, V> =
redis.connect(JsonCodec(Json, keySerializer, valueSerializer))
dave08
10/15/2024, 11:44 AMRuckus
10/15/2024, 3:38 PM