Programming-Idioms

History of Idiom 28 > diff from v24 to v25

Edit summary for version 25 :
New Scala implementation by user [meshelton]

Version 24

2016-02-16, 18:34:47

Version 25

2016-02-16, 21:58:32

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 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 type Item of the objects in items.

Code
case class S(x: Int)
val items = List(S(3), S(4), S(2))
items.sortBy( item: S => item.x )