Sha256: a296f3ebf3088a6047d5779a94e5c7181030a23b5060385cddbb9a51c36d38ad

Contents?: true

Size: 728 Bytes

Versions: 37

Compression:

Stored size: 728 Bytes

Contents

unless Enumerable.method_defined? :chunk_while
  require 'backports/tools/arguments'
  require 'backports/1.9.1/enumerator/new'

  module Enumerable
    def chunk_while(&block)
      raise ArgumentError, 'tried to create Proc object without a block' unless block
      enum = self
      Enumerator.new do |y|
        acc = []
        prev = Backports::Undefined
        enum.each do |*elem|
          elem = elem.first if elem.length == 1
          unless prev == Backports::Undefined
            unless block.call(prev, elem)
              y.yield acc
              acc = []
            end
          end
          acc << elem
          prev = elem
        end
        y.yield acc unless acc.empty?
      end
    end
  end
end

Version data entries

37 entries across 37 versions & 3 rubygems

Version Path
backports-3.25.0 lib/backports/2.3.0/enumerable/chunk_while.rb
backports-3.24.1 lib/backports/2.3.0/enumerable/chunk_while.rb
backports-3.24.0 lib/backports/2.3.0/enumerable/chunk_while.rb
backports-3.23.0 lib/backports/2.3.0/enumerable/chunk_while.rb
backports-3.22.1 lib/backports/2.3.0/enumerable/chunk_while.rb
backports-3.22.0 lib/backports/2.3.0/enumerable/chunk_while.rb
backports-3.21.0 lib/backports/2.3.0/enumerable/chunk_while.rb
backports-3.20.2 lib/backports/2.3.0/enumerable/chunk_while.rb
backports-3.20.1 lib/backports/2.3.0/enumerable/chunk_while.rb
backports-3.20.0 lib/backports/2.3.0/enumerable/chunk_while.rb
backports-3.19.0 lib/backports/2.3.0/enumerable/chunk_while.rb
backports-3.18.2 lib/backports/2.3.0/enumerable/chunk_while.rb
backports-3.18.1 lib/backports/2.3.0/enumerable/chunk_while.rb
backports-3.18.0 lib/backports/2.3.0/enumerable/chunk_while.rb
files.com-1.0.55 docs/vendor/bundle/ruby/2.5.0/gems/backports-3.12.0/lib/backports/2.3.0/enumerable/chunk_while.rb
backports-3.17.2 lib/backports/2.3.0/enumerable/chunk_while.rb
backports-3.17.1 lib/backports/2.3.0/enumerable/chunk_while.rb
backports-3.17.0 lib/backports/2.3.0/enumerable/chunk_while.rb
backports-3.16.1 lib/backports/2.3.0/enumerable/chunk_while.rb
backports-3.16.0 lib/backports/2.3.0/enumerable/chunk_while.rb