// Fusion (issue #198, ADR 0043): pure list pipelines fuse into one pass. // Both back ends run the same optimised Core, so both must print the // same. The expected outputs are computed by hand, fused or not. import std/io import std/list pub fn main :: -> () / { let xs = list.range 1 10 // map ∘ map io.println (show (list.map (list.map xs fn x { x * 2 }) fn x { x + 1 })) // the epic's pipeline: fold ∘ filter ∘ map ∘ range let doubled = list.map xs fn x { x * 2 } io.println ( show (list.fold (list.filter doubled fn x { x % 3 == 0 }) 0 fn a x { a + x }) ) // length ∘ map io.println (show (list.length (list.map xs fn x { x * 10 }))) // an effectful stage keeps its order (the gate refuses to fuse it) list.each (list.map [1, 2, 3] fn x { x * 2 }) fn x { io.println "seen {x}" } } //> [3, 5, 7, 9, 11, 13, 15, 17, 19, 21] //> 36 //> 10 //> seen 2 //> seen 4 //> seen 6