[][src]Trait kai::KaiIterator

pub trait KaiIterator: IntoIterator + Sized {
    fn chain_if<I, F>(self, condition: bool, f: F) -> ChainIf<Self, I>
    where
        I: IntoIterator<Item = Self::Item>,
        F: FnMut() -> I
, { ... } }

Generates my custom iterator adapters

For convenience, this is implmented for all types that implement not just Iterator, but IntoIterator as well.

See methods for usage.

Provided methods

Important traits for ChainIf<I, J>
fn chain_if<I, F>(self, condition: bool, f: F) -> ChainIf<Self, I> where
    I: IntoIterator<Item = Self::Item>,
    F: FnMut() -> I, 

Chain this iterator with another if the condition is true

Example

use kai::*;

let condition = true;

// Turn this
let mut v = vec![1, 2, 3];
if condition {
    v.extend(vec![4, 5, 6])
}

// Into this
let w: Vec<_> = vec![1, 2, 3].chain_if(condition, || vec![4, 5, 6]).collect();

assert_eq!(v, w);
Loading content...

Implementors

impl<I> KaiIterator for I where
    I: IntoIterator + Sized
[src]

Important traits for ChainIf<I, J>
fn chain_if<I, F>(self, condition: bool, f: F) -> ChainIf<Self, I> where
    I: IntoIterator<Item = Self::Item>,
    F: FnMut() -> I, 
[src]

Loading content...