Description

Streams is designed to be a lightweight streams processing library written in Ruby. I intend to keep this very small (infact, it’s unlikely to change at all), and have added most common methods to make it immediately useable.

Example

require ‘streams’

class Stream

def sieve
  Stream.new( head ) { tail.select { | n | n % head > 0 }.sieve }
end

end

module Math

PRIMES = 2.enumerate.sieve

end

>> Math::PRIMES.at( 30 )

> 127

>> Math::PRIMES.select { | n | n > 100 }.take( 50 )

> [101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379]