Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Kotlin – Can the minimum distance between a location and a list of locations be found with a one liner?

I would like the following "pseudocode" to be valid syntax (but clearly it’s not) :

minDistance = minOf(myLocations.forEach{return location.distanceTo(it)})

To clarify, I am trying to find the distance from the smartphone (location) to the closest location in a mutable list of locations (myLocations).

Does Kotlin allow this level of terseness, or must I break it up in a few more lines and help variables?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

I believe this is what you’re looking for

minDistance =  myLocations.minOf { location.distanceTo(it) }
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading