```fun <L, R> left(pair: Pair<L, R>): ...
# getting-started
m
Copy code
fun <L, R> left(pair: Pair<L, R>): L { return pair.first }
fun <L, R> right(pair: Pair<L, R>): R { return pair.second }

pairs.map(::left)
I can do this to transform a
List<Pair<A, B>>
into a
List<A>
.
Copy code
pairs.map(Pair::first)
I’d like to not have to define my own functions however. I’ve tried the following but they all don’t work: •
Pair::first
doesn’t compile. •
Pair<*, *>::first
compiles but returns a
List<*>
. •
Pair<VeryLongTypeName, *>::first
compiles but is verbose and brittle. What should I do?
a
personally, I would go with
pairs.map { it.first }
, or even
pairs.map { [x, _] -> x }
💯 2
c
IntelliJ has a quick-fix to use property reference syntax
But I would also just use
pairs.map { it.first }