tobogganSe connecter

louise

The Louise language: compiler, runtime, std, tooling

Clone avec HTTPS, un jeton personnel en mot de passe, ou avec SSH, une clé ajoutée dans vos paramètres.

32 lignes · 861 octetsBrut · Historique
1// Lazy iterators (issue #199, ADR 0043): pipelines over `std/iter` fuse
2// into one loop; effects in a stage's function run in pull order.
3
4import std/io
5import std/iter
6
7pub fn main :: -> () / <io>
8{
9 // The epic's pipeline shape, lazily: no intermediate lists.
10 let sum =
11 iter.range 1 100
12 |> iter.map fn x { x * 2 }
13 |> iter.filter fn x { x % 3 == 0 }
14 |> iter.fold 0 fn a x { a + x }
15 io.println (show sum)
16 // take, zip, to_list.
17 io.println (show (iter.range 1 10 |> iter.take 3 |> iter.to_list))
18 io.println
19 ( show
20 ( iter.zip (iter.range 1 5) (iter.from_list ["a", "b", "c"])
21 |> iter.to_list
22 )
23 )
24 // An effectful stage, in pull order.
25 iter.range 1 3 |> iter.each fn x { io.println "pulled {x}" }
26}
27//> 3366
28//> [1, 2, 3]
29//> [(1, a), (2, b), (3, c)]
30//> pulled 1
31//> pulled 2
32//> pulled 3