Hullaballoonatic
12/21/2019, 5:24 PMval height = points.maxBy(Point::y)!!.y - points.minBy(Point::y)!!.y
I often find myself using this schema
val height = points.map(Point::y).run { max()!! - min()!! }
uses less characters but iterates an additional time through points
of course if i really wanted to do it best by performance, i could accomplish this in only one iteration...Adam Powell
12/21/2019, 5:41 PMuses less characters but iterates an additional time throughConsider the implications of this statement; character count is not a metric you want to optimize for when the sacrifice is both runtime performance and clarity for the reader :)points
Hullaballoonatic
12/21/2019, 5:42 PMHullaballoonatic
12/21/2019, 5:42 PMHullaballoonatic
12/21/2019, 5:42 PMAdam Powell
12/21/2019, 5:46 PMIterable<Point>
and wrote the function as clearly as possible without the higher order function golf 🙂Hullaballoonatic
12/21/2019, 5:47 PMheight
into init
to be computed alongside width
and some other valuesAl Warren
01/04/2020, 6:03 AMHullaballoonatic
01/05/2020, 3:21 PM