https://github.com/bra1l0r/iterify-rs
Iterate over anything with Iterify!
https://github.com/bra1l0r/iterify-rs
functional-programming iterator rust
Last synced: about 1 year ago
JSON representation
Iterate over anything with Iterify!
- Host: GitHub
- URL: https://github.com/bra1l0r/iterify-rs
- Owner: BRA1L0R
- License: mit
- Created: 2022-07-11T23:00:17.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2022-07-11T23:04:30.000Z (over 3 years ago)
- Last Synced: 2025-02-28T07:48:39.607Z (about 1 year ago)
- Topics: functional-programming, iterator, rust
- Language: Rust
- Homepage:
- Size: 3.91 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Iterify 
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`](https://doc.rust-lang.org/std/iter/fn.successors.html) except that Iterify lets you mutate the type in-place through a `&mut` reference.
#### Example
```rust
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);
}
```