diff options
author | Tomasz Chojnacki <tomaszchojnacki2001@gmail.com> | 2023-04-06 14:41:14 +0200 |
---|---|---|
committer | Tomasz Chojnacki <tomaszchojnacki2001@gmail.com> | 2023-04-06 14:41:14 +0200 |
commit | 20852d6e60bee896e84c9bae77f45211773dbf60 (patch) | |
tree | 9e952048527a2c97a2dcd19dbdeb1d6657b5b1f1 /aoc-2020-gleam/src/ext | |
parent | bcd24674ec0a594882b276fd48fe70c6e3d7ec86 (diff) | |
download | gleam_aoc2020-20852d6e60bee896e84c9bae77f45211773dbf60.tar.gz gleam_aoc2020-20852d6e60bee896e84c9bae77f45211773dbf60.zip |
Finish day 12
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)) }, + ) +} |