summaryrefslogtreecommitdiff
path: root/rust
diff options
context:
space:
mode:
authorKjetil Orbekk <kjetil.orbekk@gmail.com>2016-06-10 23:46:13 -0400
committerKjetil Orbekk <kjetil.orbekk@gmail.com>2016-06-10 23:46:13 -0400
commitc54ce82d135c2a25bf3d88087f79659631b35e8a (patch)
treee155fc95f92a4f4fbd1136c92a8d3bf036a017ad /rust
parent695f4cec3b8216577b9ce7e0b017e23b2eb19212 (diff)
Unfold example.
Diffstat (limited to 'rust')
-rw-r--r--rust/graph/Cargo.toml4
-rw-r--r--rust/graph/unfold.rs16
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);
+ }
+}