Crates.io | iterify |
lib.rs | iterify |
version | 0.1.2 |
source | src |
created_at | 2022-07-10 21:11:55.378572 |
updated_at | 2022-07-11 23:04:35.357151 |
description | Turn any type into an iterator with closures! |
homepage | |
repository | https://github.com/BRA1L0R/iterify-rs |
max_upload_size | |
id | 623322 |
size | 3,757 |
Iterate over anything with Iterify! This crates takes any type T
and lets you iterate over a mutable reference, yielding any type you want.
It has similar behaviour to std::iter::successors
except that Iterify lets you mutate the type in-place through a &mut
reference.
use iterify::Iterify;
fn main() {
let mut num = 12;
let collatz: Vec<_> = num
.iterify(|num| {
*num = match *num {
0 | 1 => return None,
n if n % 2 != 0 => n * 3 + 1,
n => n / 2,
};
Some(*num)
})
.collect();
assert_eq!(collatz, &[6, 3, 10, 5, 16, 8, 4, 2, 1]);
assert_eq!(num, 1);
}