summaryrefslogtreecommitdiff
path: root/rust/graph/unfold.rs
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/graph/unfold.rs
parent695f4cec3b8216577b9ce7e0b017e23b2eb19212 (diff)
Unfold example.
Diffstat (limited to 'rust/graph/unfold.rs')
-rw-r--r--rust/graph/unfold.rs16
1 files changed, 16 insertions, 0 deletions
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);
+ }
+}