I would find a List.sortBy function convenient. It would sort by the result of a function (or record property). You could use it like this.
input
|> Str.split "\n"
|> List.map createPerson
|> List.sortBy .age
It could be implemented like this.
sortBy = \list, func ->
List.sortWith list \a, b ->
Num.compare (func a) (func b)
I'm not sure about sorting descending, perhaps it needs sortAscBy and sortDescBy?
List.sortAscBy and List.sortDescBy are listed as todo in #664
Glad to see it's planned, thanks!
Ryan Bates has marked this topic as resolved.
Last updated: Jun 16 2026 at 16:19 UTC