// Lazy iterators (issue #199, ADR 0043): pipelines over `std/iter` fuse // into one loop; effects in a stage's function run in pull order. import std/io import std/iter pub fn main :: -> () / { // The epic's pipeline shape, lazily: no intermediate lists. let sum = iter.range 1 100 |> iter.map fn x { x * 2 } |> iter.filter fn x { x % 3 == 0 } |> iter.fold 0 fn a x { a + x } io.println (show sum) // take, zip, to_list. io.println (show (iter.range 1 10 |> iter.take 3 |> iter.to_list)) io.println ( show ( iter.zip (iter.range 1 5) (iter.from_list ["a", "b", "c"]) |> iter.to_list ) ) // An effectful stage, in pull order. iter.range 1 3 |> iter.each fn x { io.println "pulled {x}" } } //> 3366 //> [1, 2, 3] //> [(1, a), (2, b), (3, c)] //> pulled 1 //> pulled 2 //> pulled 3