Is there by any chance an equivalent in Kotlin of ...
# announcements
s
Is there by any chance an equivalent in Kotlin of .NET
Enumerable.Select
to convert from enumeration<type1> to enumeration<type2>? Thanks!
b
.map { it.totype2() }
s
I'm not sure I follow. I would have to apply/provide some kind of transform method (such as
fun transform(t1: Type1): Type2
) because Type1 and Type2 are custom types. Digging a little further, it looks like
associateTo
might do the trick, wouldn't it?
Well,
associateTo
seems to imply a
Map
as return type, so not quite what I'm looking for, but closing in...
b
map does exactly what you want
listOf(1, 2, 3).map { it * 2} // 2,4,6 as result
s
Ah, ok I misunderstood you at first. Thanks Denis!
b
in c# you will write something like:
users.Select(u => u.name)
in kotlin it
users.map { it.name }
or
users.map {u -> u.name}
which make it more similar to c#