mirror of
https://github.com/lloeki/ruby-tee.git
synced 2025-12-06 10:34:42 +01:00
gem, specs, README, and general consistency
This commit is contained in:
parent
31d6fa48c0
commit
ef0fffd385
18 changed files with 431 additions and 124 deletions
31
README.md
Normal file
31
README.md
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
# 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.
|
||||
|
||||
```ruby
|
||||
> 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.
|
||||
|
||||
```ruby
|
||||
> 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.
|
||||
Loading…
Add table
Add a link
Reference in a new issue