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

Version Path
facets-2.9.3 lib/core/facets/enumerable/cluster_by.rb
facets-2.9.2 lib/core/facets/enumerable/cluster_by.rb
facets-2.9.2 src/core/facets/enumerable/cluster_by.rb
facets-2.9.1 lib/core/facets/enumerable/cluster_by.rb
facets-2.9.0 lib/core/facets/enumerable/cluster_by.rb
facets-2.9.0.pre.2 lib/core/facets/enumerable/cluster_by.rb
facets-2.9.0.pre.1 lib/core/facets/enumerable/cluster_by.rb