Sha256: 5eccc65875ca4bfd7c666cb3831cc2ad97521274f35e1595351d6d565ce44a2f

Contents?: true

Size: 401 Bytes

Versions: 109

Compression:

Stored size: 401 Bytes

Contents

# frozen_string_literal: true

class ReeArray::GroupBy
  include Ree::FnDSL

  fn :group_by

  contract(
    ArrayOf[Any], Block => HashOf[Any, ArrayOf[Any]]
  )
  def call(list, &proc)
    result = {}

    list.each do |element|
      key = yield(element)

      if result.has_key?(key)
        result[key] << element
      else
        result[key] = [element]
      end
    end

    result
  end
end

Version data entries

109 entries across 109 versions & 1 rubygems

Version Path
ree_lib-1.0.109 lib/ree_lib/packages/ree_array/package/ree_array/functions/group_by.rb
ree_lib-1.0.108 lib/ree_lib/packages/ree_array/package/ree_array/functions/group_by.rb
ree_lib-1.0.107 lib/ree_lib/packages/ree_array/package/ree_array/functions/group_by.rb
ree_lib-1.0.106 lib/ree_lib/packages/ree_array/package/ree_array/functions/group_by.rb
ree_lib-1.0.105 lib/ree_lib/packages/ree_array/package/ree_array/functions/group_by.rb
ree_lib-1.0.104 lib/ree_lib/packages/ree_array/package/ree_array/functions/group_by.rb
ree_lib-1.0.103 lib/ree_lib/packages/ree_array/package/ree_array/functions/group_by.rb
ree_lib-1.0.102 lib/ree_lib/packages/ree_array/package/ree_array/functions/group_by.rb
ree_lib-1.0.101 lib/ree_lib/packages/ree_array/package/ree_array/functions/group_by.rb
ree_lib-1.0.100 lib/ree_lib/packages/ree_array/package/ree_array/functions/group_by.rb
ree_lib-1.0.99 lib/ree_lib/packages/ree_array/package/ree_array/functions/group_by.rb
ree_lib-1.0.98 lib/ree_lib/packages/ree_array/package/ree_array/functions/group_by.rb
ree_lib-1.0.97 lib/ree_lib/packages/ree_array/package/ree_array/functions/group_by.rb
ree_lib-1.0.96 lib/ree_lib/packages/ree_array/package/ree_array/functions/group_by.rb
ree_lib-1.0.95 lib/ree_lib/packages/ree_array/package/ree_array/functions/group_by.rb
ree_lib-1.0.94 lib/ree_lib/packages/ree_array/package/ree_array/functions/group_by.rb
ree_lib-1.0.93 lib/ree_lib/packages/ree_array/package/ree_array/functions/group_by.rb
ree_lib-1.0.92 lib/ree_lib/packages/ree_array/package/ree_array/functions/group_by.rb
ree_lib-1.0.91 lib/ree_lib/packages/ree_array/package/ree_array/functions/group_by.rb
ree_lib-1.0.90 lib/ree_lib/packages/ree_array/package/ree_array/functions/group_by.rb