version 1: ```class MyList<T> : List { // .....
# getting-started
y
version 1:
Copy code
class MyList<T> : List {
// ...
  fun MyList<Pair<T,R>>.unzip(): Pair<MyList<T>, MyList<R>> { //implementation similar to Iterable.unzip() }
}
version 2:
Copy code
class MyList<T> : List {
// ...
}

fun MyList<Pair<T,R>>.unzip(): Pair<MyList<T>, MyList<R>> { //implementation similar to Iterable.unzip() }
in version 1, Kotlin (well, IntelliJ) complains that the receiver parameter is never used in
unzip()
, but it doesn't complain in version 2. is there a different way to define version 1 so that it won't complain?
s
No, you can’t really do that. You’d need to make a subclass like
MyListOfPairs<L, R>: MyList<Pair<L, R>>
and define the member function there. But version 2 is more flexible — I’d just use that.
The question is actually quite similar to this one: https://kotlinlang.slack.com/archives/C0B8MA7FA/p1683189305425929
If you have a receiver parameter of the same type as the containing class, that would actually result in two different receivers. That’s why you get the warning. You can’t use extension receiver syntax to restrict the type of the existing dispatch receiver.
y
I understand. thank you