Method: Immutable::List#sort_by
- Defined in:
- lib/immutable/list.rb
#sort_by {|element| ... } ⇒ List
Return a new List with the same items, but sorted. The sort order is determined by mapping the items through the given block to obtain sort keys, and then sorting the keys according to their natural sort order (‘#<=>`).
575 576 577 578 |
# File 'lib/immutable/list.rb', line 575 def sort_by(&transformer) return sort unless block_given? LazyList.new { List.from_enum(super(&transformer)) } end |