#collection #lazy-evaluation #strict #traversable

iterable

An iterable library for Rust collection like types

7 releases (breaking)

0.6.0 Dec 8, 2022
0.5.0 Feb 7, 2022
0.4.1 May 26, 2021
0.4.0 Oct 1, 2020
0.1.0 Sep 23, 2020

#647 in Data structures

Download history 1962/week @ 2024-08-05 1687/week @ 2024-08-12 2554/week @ 2024-08-19 3064/week @ 2024-08-26 2657/week @ 2024-09-02 2531/week @ 2024-09-09 2303/week @ 2024-09-16 2131/week @ 2024-09-23 1627/week @ 2024-09-30 1051/week @ 2024-10-07 1152/week @ 2024-10-14 1410/week @ 2024-10-21 1239/week @ 2024-10-28 1752/week @ 2024-11-04 2045/week @ 2024-11-11 1488/week @ 2024-11-18

6,534 downloads per month
Used in 3 crates (2 directly)

MIT license

80KB
3K SLoC

Iterable

An iterable library for Rust collection like types.

Installation

# Cargo.toml
[dependencies]
iterable = "0.6"

Features

iterate collection like types without iter() and collect():

use iterable::*;

fn main() {
    // convert a vec of i32 to a vec of String
    let v = vec![1, 2, 3];
    // only one `map` function instead of `v.iter().map(|i| i.to_string()).collect()`
    let res = v.map(|i| i.to_string());
    assert_eq!(res, vec!["1".to_string(), "2".to_string(), "3".to_string()]);

    // iterable also support array and string
    let v = [1, 2, 3];
    // res's type: [i32; 3]
    let res = v.rev();
    assert_eq!(res, [3, 2, 1]);
    
    // lazy combinator
    let v = vec![1,2,3];
    let s = v
        .lazy_filter(|x| x > &1)
        .lazy_map(|x| x.to_string())
        .rev();
    assert_eq!(s, vec!["3".to_string(), "2".to_string()]);

    // iterate over reference
    let v = vec![1, 2, 3];
    let res = (&v).filter(|i| i > &&1);
    assert_eq!(res, vec![&2, &3]);

    // functional append
    let a = vec![1, 2, 3];
    let res = a.add_one(1);
    assert_eq!(res, vec![1, 2, 3 ,1]);

    // a bunch of try methods: try_map, try_add_one, try_flat_map, try_flatten
    let a = vec![1, 2, 3];
    let res = a.try_map(|x| Some(x));
    assert_eq!(res, Some(vec![1, 2, 3]));

    let a = vec![1, 2, 3];
    let res: Result<_,()> = a.try_map(|x| Ok(x));
    assert_eq!(res, Ok(vec![1, 2, 3]));
}

License

MIT

Dependencies

~425KB