Teeing enumerations into procs
Find a file
2013-10-22 18:23:24 +02:00
lib gem, specs, README, and general consistency 2013-10-22 18:23:24 +02:00
spec gem, specs, README, and general consistency 2013-10-22 18:23:24 +02:00
.gitignore gem, specs, README, and general consistency 2013-10-22 18:23:24 +02:00
.rspec gem, specs, README, and general consistency 2013-10-22 18:23:24 +02:00
.rubocop.yml gem, specs, README, and general consistency 2013-10-22 18:23:24 +02:00
Gemfile gem, specs, README, and general consistency 2013-10-22 18:23:24 +02:00
Gemfile.lock gem, specs, README, and general consistency 2013-10-22 18:23:24 +02:00
Guardfile gem, specs, README, and general consistency 2013-10-22 18:23:24 +02:00
LICENSE gem, specs, README, and general consistency 2013-10-22 18:23:24 +02:00
Rakefile gem, specs, README, and general consistency 2013-10-22 18:23:24 +02:00
README.md gem, specs, README, and general consistency 2013-10-22 18:23:24 +02:00
tee.gemspec gem, specs, README, and general consistency 2013-10-22 18:23:24 +02:00

Tee

Allows Enumerables and IO objects to be teed via fibers.

Examples

Teeing enumerables makes each proc receive its own enumerator. #tee returns an array with each proc's return values.

> require 'tee/core_ext'
> [1, 2, 3].tee -> (e) { e.reduce(&:+) },
                -> (e) { e.map { |i| i**2 } }
=> [6, [1, 4, 9]]

Teeing IOs makes each proc receive its own IO. Those IOs can read the incoming data in chunks.

> require 'tee/core_ext'
> StringIO.new("foo").tee -> (io) { io.chunks.each { |c| puts c } }
foo
=> [nil]

Data can currently only be read in whole, uniformly sized chunks. Concurrent execution is achieved via fibers (no threads needed).

One can skip requiring core_ext and get #tee on a case by case basis by including or extending Enumerable::Tee and IO::Tee modules.