https://github.com/champii/eziter
Iterators made easy
https://github.com/champii/eziter
Last synced: 3 months ago
JSON representation
Iterators made easy
- Host: GitHub
- URL: https://github.com/champii/eziter
- Owner: Champii
- License: mit
- Created: 2022-05-13T02:00:42.000Z (about 3 years ago)
- Default Branch: master
- Last Pushed: 2022-06-14T11:41:04.000Z (about 3 years ago)
- Last Synced: 2025-03-12T12:40:03.830Z (4 months ago)
- Language: Rust
- Size: 10.7 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# EzIter
Iterators made easy## Usage
Add this line into your `Cargo.toml`
```toml
eziter = "0.1"
```and add a use statement at the top of every module using `EzIter`
```rust
use eziter::*;
```## What is this ?
This crate contains some conveniance wrappers around rust's iterators and std collections.
Theses are essentially useful in the rare cases where you only want to use a single map or
filter on your iterator without the syntactic burden of unrolling a full `x.iter().map(f).collect();`.
You can instead write a more appeiling `x.map(f);`Only a handful of methods are actually implemented, more might come in the future:
```rust
x.map(f);
x.filter(f);
x.filter_map(f);
x.skip_while(f);
x.take_while(f);
x.map_while(f);
```Each of theses come in 3 flavors, here an example with `map`
```rust
x.into_map(f);
x.map(f);
x.map_mut(f);
```That corresponds to
```rust
x.into_iter().map(f).collect();
x.iter().map(f).collect();
x.iter_mut().map(f).collect();
```You can use theses wrappers out of the box with the standard collections
```rust
HashMap
BTreeMap
HashSet
BTreeSet
BinaryHeap
LinkedList
Vec
VecDeque
```but note that the `*_mut()` variations are not available for
```rust
HashSet
BTreeSet
BinaryHeap
```You also gain usage of all `into_*()` wrappers for every implementors of `IntoIterator`
## Example
```rust
use eziter::*;fn main() {
let v = vec![1, 2, 3];let _res: Vec<_> = v.map(|x| x + 3);
}
```## Caveats
Please note that theses wrappers don't come for free.
### No chainable calls
First, you will lose the ability to chain theses calls together.
I mean, you *could* chain them, but they would all individually call the `.collect()` method,
leaving you with an increasing waste of resources as the chain grows.
The rust's Iterators are the way to go in that case, obviously.### Extra `Box<>` allocation
In order for the implementation to hold, only the `into_*()` wrappers come really free of charge,
the others produced iterators are wrapped around a `Box`. If you don't mind the extra
allocation/deallocation, you are fine.
This might change in the future when rust will allow to return `impl`s from trait implementation.