Hi! Still learning functional things in Kotlin and...
# codereview
z
Hi! Still learning functional things in Kotlin and would need some help. Can someone please check my example and tell me if this example can be done better? https://try.kotlinlang.org/#/UserProjects/h9ra2isjl4vudcq3mmo8gii4n8/fb6lvfgtq7ppf3es5tt36b5h0o Thanks! [moved from #general]
h
I'm not sure what you're looking for, but I made https://pl.kotl.in/ry51qAM0m
z
I was thinking if there exists any extra magical functional construct to do that in one step, not making multiple lists or maps 🙂 Thanks, looks much prettier solution
a
You can also do:
Copy code
users
    .filterNot { it.state == 5 }
    .groupingBy { it.id }
    .reduce { _, acc, user ->
        maxOf(acc, user, compareBy { it.state })
    }
    .values
z
Thanks! Looks nicer and reduce is not nullable (mapValues is).
e
There is
mapNotNull{}
as a non-null version of
map{}