diff options
-rw-r--r-- | rust/graph/Cargo.toml | 4 | ||||
-rw-r--r-- | rust/graph/unfold.rs | 16 |
2 files changed, 20 insertions, 0 deletions
diff --git a/rust/graph/Cargo.toml b/rust/graph/Cargo.toml index eb0841b..1cd21d8 100644 --- a/rust/graph/Cargo.toml +++ b/rust/graph/Cargo.toml @@ -13,3 +13,7 @@ path = "graph.rs" [[bin]] name = "graph2" path = "graph2.rs" + +[[bin]] +name = "unfold" +path = "unfold.rs" diff --git a/rust/graph/unfold.rs b/rust/graph/unfold.rs new file mode 100644 index 0000000..90de74c --- /dev/null +++ b/rust/graph/unfold.rs @@ -0,0 +1,16 @@ +extern crate itertools; + +use itertools::Unfold; + +fn main() { + for n in Unfold::new(1, |state| { + if *state < 100 { + *state += 1; + Some(*state) + } else { + None + } + }) { + println!("{}", n); + } +} |