Check if `t` is `Iterable` inside your `concat`, a...
# announcements
e
Check if
t
is
Iterable
inside your
concat
, and skip the
listOf(t)
is true
k
Yikes, I'd just create a new function at this point.
n
But… it all looks strange and buggy. In Kotlin I mean.
k
Just go with the infix one.
n
With concat same thing. So it’s not a problem of plus operator.
k
Right, but the problem is that
+
is defined to combine two lists by the stdlib, so basically you're breaking it.
n
Well… if you write
1 + listOf(2)
you receive
undefined
. So what does it break?
k
The problem is that you break
listOf(1) + listOf(2)
as well.
n
Yes. I think it’s a bug in kotlin. Because List< T> != T.
For example if you define concat with
Int
instead of generic
T
it won’t break concat of two lists, it will say type error. And it’s correct.
e
I don't think its a bug,
T
is just a over generalised type, if you don't give any bound to it, it can be anything
👍 1
k
Well no, the compiler just picks
T = Any
and then they both match.
e
Make your
T
more specific to the type your want to affect
n
Ok. How should I define T to succeed
List< T> != T
?
e
Maybe
T: List<*>
?
k
Well that's the point, it should work for everything but Iterable, and I don't think that's possible.
n
Also Collection defines a plus operator. But as I said it’s not only a problem of plus operator.
I’ll try more later. Thanks for suggestions. 🙂
k
Collection defines a more specific method that can be more performant than the iterator one in some cases, but that's not a problem because the bahavior is exactly the same.