Trait iter_python::extension_traits::IteratorExt[][src]

pub trait IteratorExt: Sized + Iterator {
    fn vec<T>(self) -> Vec<T>
    where
        Self: Iterator<Item = T>
, { ... }
fn dict<K, V>(self) -> HashMap<K, V>
    where
        Self: Iterator<Item = (K, V)>,
        K: Hash + Eq
, { ... } }
This is supported on crate feature std only.
Expand description

Provides a convenience .vec() and .dict() adapters to collect an i!(…) iterator expression into a Vec and a HashMap respectively.

Example

use ::iter_python::prelude::*;

assert_eq!(
    i!(x for x in 0 .. 5).vec(),
    v![x for x in 0 .. 5],
);

assert_eq!(
    i!((x, x * x) for x in 1 ..= 2).dict(),
    {
        let mut map = ::std::collections::HashMap::new();
        map.insert(1, 1);
        map.insert(2, 4);
        map
    },
);

Provided methods

Implementors