-{ extension "lazy" }
-{ extension "ternary" }

--require "stream"
dofile "samples/stream.luac"

ints   = %{ hd = 1; tl = stream.map (|x| x+1, ints) }

not_divided_by = |n||x| x%n ~= 0

rec = |s| s ? %{ hd = s.hd, 
                 tl = rec (stream.filter (not_divided_by (s.hd), s.tl)) }, 
              stream.empty 

primes = rec (ints.tl)

table.print(stream.take (100, primes))

x = stream.create (1, 2, 3)
a = |s,n| stream.map (|x| x+n, s)
y = stream.create (x, a(x,10), a(x,20))
z = stream.flatten (y)

table.print(stream.take (nil, z))
/body>