Sha256: ed6a8038a68d5203e85923ec9ebe04e97166bc594227a1f000ebce423521134a

Contents?: true

Size: 441 Bytes

Versions: 1

Compression:

Stored size: 441 Bytes

Contents

require_relative "../hash/putbang"

module Enumerable

  # Converts the Enumerable into a Hash, using its elements as keys and
  # using the given block to compute an associated value for each key.
  #
  # @example
  #   cache = id_list.index_to{|id| find_by_id(id) }
  #
  # @yield [key]
  # @yieldparam key ['K]
  # @yieldreturn ['V]
  # @return [Hash<'K, 'V>]
  def index_to()
    self.reduce({}){|h, k| h.put!(k, (yield k)) }
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
casual_support-3.0.2 lib/casual_support/enumerable/index_to.rb