Sha256: 8d5570f9cec1802501382fb3f6255ed50e3d1ed72b6012a686fbeab53f0d3258

Contents?: true

Size: 588 Bytes

Versions: 3

Compression:

Stored size: 588 Bytes

Contents

# frozen_string_literal: true

class Enumark

  class Grouping
    Group = Struct.new(:name, :items)

    def initialize(enumark, key, &post)
      @lock = Mutex.new
      @collection = nil

      @enumark = enumark
      @key = key
      @post = post
    end

    def each(&block)
      unless @collection
        @lock.synchronize do
          @collection = @enumark.group_by(&@key)
          @collection = @post.call(@collection) if @post
          @collection = @collection.map{ |k, items| Group.new(k, items) }
        end
      end

      @collection.each(&block)
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
enumark-1.1.1 lib/enumark/grouping.rb
enumark-1.0.0 lib/enumark/grouping.rb
enumark-0.1.4 lib/enumark/grouping.rb