Sha256: ec37538de2f75d2d1a2433fdab4a5893ad22f01e886b675e03e17e0ba4963b41

Contents?: true

Size: 378 Bytes

Versions: 7

Compression:

Stored size: 378 Bytes

Contents

require 'facets/functor'

module Enumerable

  # Accumulate a set of a set.
  #
  # For example, in an ORM design if Group
  # has_many User then
  #
  #   groups.accumulate.users
  #
  # will return a list of users from all groups.

  def accumulate
    @_accumulate ||= Functor.new do |op, *args|
      inject([]) { |a, x| a << x.send(op, *args) }.flatten
    end
  end

end

Version data entries

7 entries across 7 versions & 2 rubygems

Version Path
facets-2.4.0 lib/facets/enumerable/accumulate.rb
facets-2.4.1 lib/facets/enumerable/accumulate.rb
facets-2.4.3 lib/core/facets/enumerable/accumulate.rb
facets-2.4.2 lib/core/facets/enumerable/accumulate.rb
facets-2.4.4 lib/core/facets/enumerable/accumulate.rb
facets-2.4.5 lib/core/facets/enumerable/accumulate.rb
mack-facets-0.8.2 lib/gems/facets-2.4.5/lib/core/facets/enumerable/accumulate.rb