Programming-Idioms

History of Idiom 28 > diff from v41 to v42

Edit summary for version 42 :
[Elixir] Simpler implementation

Version 41

2018-02-14, 12:52:36

Version 42

2018-02-14, 15:39:34

Idiom #28 Sort by a property

Sort elements of array-like collection items in ascending order of x.p, where p is a field of the type Item of the objects in items.

Idiom #28 Sort by a property

Sort elements of array-like collection items in ascending order of x.p, where p is a field of the type Item of the objects in items.

Code
Enum.sort(items, &(&1.p <= &2.p))
Code
Enum.sort_by(items, &(&1.p))
Doc URL
http://elixir-lang.org/docs/v1.0/elixir/Enum.html#sort/2
Doc URL
https://hexdocs.pm/elixir/Enum.html#sort_by/3
Demo URL
http://play.elixirbyexample.com/s/9ab4ff24fb
Demo URL
http://play.elixirbyexample.com/s/9ab4ff24fb