unfold 0.2.0

A simple unfold implementation in Rust
Documentation
  • Coverage
  • 100%
    7 out of 7 items documented5 out of 7 items with examples
  • Size
  • Source code size: 8.13 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 480.1 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 9s Average build duration of successful builds.
  • all releases: 9s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • FilippoRanza/unfold
    1 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • FilippoRanza

unfold

Rust crates.io

A simple unfold implementation in Rust

unfold 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

use unfold::Unfold;

// Create a vector containing the first 5 numbers from the Fibonacci
// series
let fibonacci_numbers: Vec<u64> = 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);