Sha256: 6755084caf6df0ab2ca63b9678cc09f118343c8e2eb16c1c46fe62e6bd853bda
Contents?: true
Size: 411 Bytes
Versions: 10
Compression:
Stored size: 411 Bytes
Contents
require 'facets/enumerable/group_by' module Enumerable # Similar to #group_by but returns an array of the groups. # Returned elements are sorted by block. # # %w{this is a test}.cluster_by {|x| x[0]} # # _produces_ # # [ ['a'], ['is'], ['this', 'test'] ] # # CREDIT: Erik Veenstra def cluster_by(&b) group_by(&b).sort.transpose.pop || [] # group_by(&b).values ? end end
Version data entries
10 entries across 10 versions & 1 rubygems