karelpeeters
05/11/2019, 5:54 PM<?>
stuff 😒imple_smile:gabrielfv
05/11/2019, 5:55 PMkarelpeeters
05/11/2019, 5:55 PMgabrielfv
05/11/2019, 5:57 PMkarelpeeters
05/11/2019, 6:01 PMin
works for me:
fun <T: Any> Producer<T?>.consume(consume: (T) -> Unit) {
attachConsumer { it?.let(consume) }
}
?
, I'm not sure why that is missing)gabrielfv
05/11/2019, 6:03 PMkarelpeeters
05/11/2019, 6:09 PMattachConsumerDropNulls
or something. It's easy to forget values are silently being dropped here when using this.gabrielfv
05/11/2019, 6:12 PMobserveNonNulls()
karelpeeters
05/11/2019, 6:12 PMgabrielfv
05/11/2019, 6:18 PMT?
, wouldn't it make setting our upper bound of T
to Any
redundant?T?
that the upper bound Any?
doesn't make sense, and make it Any
.karelpeeters
05/11/2019, 6:19 PMgabrielfv
05/11/2019, 6:19 PM<T : Any?> ... <T?>
. That's interesting.karelpeeters
05/11/2019, 6:22 PMprod.consume<String?> { }
.gabrielfv
05/11/2019, 6:38 PM<T> ... <T?>
will tell the compiler that my consumer can both consume nullable types or not, whereas my producer will always produce nullable.<T : Any>
will assert that my consumer will never be consuming nullables.<T> ... <T?>
only worked for me because my producer was of T!
, but if it was T?
, the compiler wouldn't be able to infer it alike. Gotta give it a try
Gave it a try: It still infers the non-null variant.karelpeeters
05/11/2019, 6:40 PMAny?
would be fine too. That why it doesn't matter in this case.
package kotlin.jvm.functions
public interface Function1<in P1, out R> : kotlin.Function<R> {
public abstract operator fun invoke(p1: P1): R
}
gabrielfv
05/11/2019, 6:43 PMkarelpeeters
05/11/2019, 6:43 PM