diff options
Diffstat (limited to 'aoc-2020-gleam/src/ext')
-rw-r--r-- | aoc-2020-gleam/src/ext/iteratorx.gleam | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/aoc-2020-gleam/src/ext/iteratorx.gleam b/aoc-2020-gleam/src/ext/iteratorx.gleam index 65e06f2..4e184bd 100644 --- a/aoc-2020-gleam/src/ext/iteratorx.gleam +++ b/aoc-2020-gleam/src/ext/iteratorx.gleam @@ -1,4 +1,4 @@ -import gleam/iterator.{Iterator} as iter +import gleam/iterator.{Iterator, Next} as iter pub fn length(iterator: Iterator(a)) -> Int { iterator @@ -23,3 +23,10 @@ pub fn filter_map( } }) } + +pub fn unfold_infinitely(from state: a, with fun: fn(a) -> a) -> Iterator(a) { + iter.unfold( + from: state, + with: fn(s) { Next(element: s, accumulator: fun(s)) }, + ) +} |