Sha256: 5800f17c9a2ba8e2925b307154443636d7fdf052e75149f14a62380f66f7bf73

Contents?: true

Size: 414 Bytes

Versions: 10

Compression:

Stored size: 414 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.
  #
  # CREDIT: George Moshchovitis

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

end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
facets-2.8.4 lib/core/facets/enumerable/accumulate.rb
facets-2.8.3 lib/core/facets/enumerable/accumulate.rb
facets-2.8.2 lib/core/facets/enumerable/accumulate.rb
facets-2.8.1 lib/core/facets/enumerable/accumulate.rb
facets-2.8.0 lib/core/facets/enumerable/accumulate.rb
facets-2.7.0 lib/core/facets/enumerable/accumulate.rb
facets-2.6.0 lib/core/facets/enumerable/accumulate.rb
facets-2.5.0 lib/core/facets/enumerable/accumulate.rb
facets-2.5.1 lib/core/facets/enumerable/accumulate.rb
facets-2.5.2 lib/core/facets/enumerable/accumulate.rb