all, I'm working through the kotlin koans, but the...
# getting-started
j
all, I'm working through the kotlin koans, but the generics section trips me up a bit. I've been away from java for sometime, so humour me. In "fun <T, C:MutableCollection<T>> Collection<T>.partitionTo(first: C, second: C, predicate: (T) -> Boolean): Pair<C, C>", how should one read "<T, C: MutableCollection<T>>"? As I understand it, the code preceding the function name is the type parameter...but in this case, what is it stating the type is? The "," is throwing me for a loop...
p
T and C are both type parameters. Here we are extending MutableCollection of Ts with a method partitionTo that takes two Cs and a predicate from T to Boolean
j
@pavel Thanks. Is there some docs which cover type parameters and their format/use? Should I understand it as "you can have any many type parameters as you want to use in your function, but just separate them with commas"? So I could have "fun <a,b,c,d,e,f> myFunc(..."
p
There might be a limit set by the compiler
j
@pavel Sure, but I'm understanding it correctly right? that the <> before the function name can accept 1..n type parameters (where n may be limited by the compiler)?
p
yes
j
@pavel Ok, great. thanks. I think that clears it up. I have read that Kotlin page many times but it doesn't really go into type params that much. since I haven't been using java as much since generics came out, maybe the kotlin docs assume some knowledge of java generics syntax?
p
probably, when I played around with those I just assumed they worked the same as in Java and had no issues
j
@pavel great...thanks very much for your help