https://github.com/filipporanza/unfold
A simple unfold implementation in Rust
https://github.com/filipporanza/unfold
iterator iterator-library library rust unfold
Last synced: about 1 month ago
JSON representation
A simple unfold implementation in Rust
- Host: GitHub
- URL: https://github.com/filipporanza/unfold
- Owner: FilippoRanza
- License: mit
- Created: 2021-01-14T19:21:52.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2021-01-19T19:08:08.000Z (over 4 years ago)
- Last Synced: 2025-04-14T22:56:23.369Z (about 1 month ago)
- Topics: iterator, iterator-library, library, rust, unfold
- Language: Rust
- Homepage: https://crates.io/crates/unfold
- Size: 11.7 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# unfold
 A simple unfold implementation in Rust
[unfold](https://en.wikipedia.org/wiki/Fold_(higher-order_function)) let you
create an iterator that, staring from a given initial value,
applies a given function to the current state, store the result for
the next iteration, and return the current state.Unfold defines an endless iterator: you must stop it *by hand*, like in the
example.## Example
```rust
use unfold::Unfold;// Create a vector containing the first 5 numbers from the Fibonacci
// series
let fibonacci_numbers: Vec = Unfold::new(|(a, b)| (b, a + b), (0, 1))
.map(|(a, _)| a)
.take(5) //Unfold iterator never stops.
.collect();
assert_eq!(vec![0, 1, 1, 2, 3], fibonacci_numbers);
```