Suppose I want to get the lowest property of an ob...
# codereview
d
Suppose I want to get the lowest property of an object in an array of said objects, might there be a better way than:
source.minBy { it.startX }?.startX ?: 0
Maybe a way to get the value of the property directly from the collection instead the object which it belongs to?
k
ferranis:
source.map { it.startX }.min() ?: 0
d
Thank you for your reply! This seems to at least remove the indirection over the object
👍 1
k
you can also use a method reference here. I dunno what your source class name is, but if the class name is
Foo
,
source.map(Foo::startX).min() ?: 0
, if you think that looks cleaner
d
Thank you again! I didn't use this till now but this is a nice way to flatten the expression a bit! 🙂