25 lines
777 B
Markdown
25 lines
777 B
Markdown
# infiniyield
|
|
|
|
Infinitely unfold values on-demand from a function.
|
|
|
|
[](https://hex.pm/packages/infiniyield)
|
|
[](https://hexdocs.pm/infiniyield/)
|
|
|
|
The library allows you to operate on an infinite sequence of values, retrieving values from the sequence as required.
|
|
|
|
```sh
|
|
gleam add infiniyield@1
|
|
```
|
|
```gleam
|
|
import infiniyield
|
|
|
|
pub fn main() {
|
|
infiniyield.unfold(2, fn(acc) { infiniyield.Next(acc, acc * 2) })
|
|
|> infiniyield.take(5)
|
|
// -> [2, 4, 8, 16, 32]
|
|
}
|
|
```
|
|
|
|
Based on the [gleam_yielder](https://hexdocs.pm/gleam_yielder) library by [Louis Pilfold](https://github.com/lpil).
|
|
|
|
Further documentation can be found at <https://hexdocs.pm/infiniyield>.
|