Skip to content

j-kish/simple_iterator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SimpleIterator

Installation

Add this line to your application's Gemfile:

gem 'simple_iterator'

And then execute:

$ bundle

Or install it yourself as:

$ gem install simple_iterator

Usage

itr = SimpleIterator::Plain.new(
  offset:           0,
  increment_offset: 100,
  next_cb:          lambda { |current_offset|
    users = User.offset(current_offset).limit(100)
    users.length > 0 ? users : nil
  }
)

while (users = itr.next)
  users.each do |user|
    p user
  end
end
itr = SimpleIterator::File.new(
  file_path:        tsv_file,
  separate:         "\t",
  increment_lines:  1000,
  line_separate_cb: lambda { |row|
    {
      id:   row[0],
      name: row[1]
    }
  }
)

while (rows = itr.next)
  rows.each do |row|
    p row[:id]
    p row[:name]
  end
end

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/jkishimoto/simple_iterator.

License

The gem is available as open source under the terms of the MIT License.

About

Simple iterator

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published