Sha256: 868ebf57082ed6e4d0684435bd658d939495962cba72f7b3da17398f6078ef2f
Contents?: true
Size: 392 Bytes
Versions: 7
Compression:
Stored size: 392 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]} # #=> [ ['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
7 entries across 6 versions & 1 rubygems