is there an idiomatic way to get multiple mins if ...
# announcements
a
is there an idiomatic way to get multiple mins if they are
==
?
r
If they are equal, why would you need multiple?
a
@Ruckus if I am using
minBy{...}
it might be nice since the contents of the actual object might be different
r
I can't think of a way to do that logically in one step. You'd need to do something like:
Copy code
val thing = things.minBy { it.value}
val found = things.filter { it.value = thing.value }
a
yeah... inefficient but clean
I mean 2x slower than most performant way
but probably not bad
kinda a micro-optimization to make a whole other func imo
r
Maybe, but I can't think of a more performant way to do it in one pass. You'd have to maintain a list of all matching found records as you go, throwing the list out every time a smaller value is found. You'd have to benchmark it, but I could see that kind of overhead being comparable to two iterations.
a
perhaps you're right
r
Ignoring performance, it could be useful if the thing you're iterating over doesn't handle multiple iterations.
I guess if you needed to, you could group by the property, get the min key, and get the values for that key. Don't know how heavy that is from a performance perspective though.