[][src]Struct cor_iter::LinearCorIter

pub struct LinearCorIter<I, J, T> where
    I: Iterator,
    J: Iterator,
    T: PrimInt
{ /* fields omitted */ }

Linear correlation by number of item based on primary and secondary iterator. It take two co-efficient a and b of any subtype of Int.

It use sign of co-efficient to determine which iterator should yield items. There's two set of rules for this iterator.

First set of rules are:

  • If b > 0, first b element will come from primary iterator.
  • If b < 0, first b element, return from secondary iterator.
  • If b == 0, it will proceed to below set of rules

After above set of rules is applied, then following rules will apply:

  • If a > 0, it return a elements from primary then one element from secondary
  • If a < 0, it return a elements from secondary then one element from primary.
  • If a == 0, it return None

For a case where a = 1 and b = 0. It will return an interleave value between primary and secondary iterator. If both iterator return value of the same kind, consider interleave function from itertools. Another option is to use zip method from primary iterator. It will return a pair of value from both iterator at once. It will be much more efficient than evaluating each item on each iteration.

This iterator is lazy. It won't iterate on any of iterators until it own self has been iterate.

Example

If a = 2, b = 1 then

  1. First item will come from primary iterator
  2. Two items from primary iterator
  3. One item from secondary iterator
  4. Go back to step 2 until one of iterator return None

If a = -2, b = 1 then

  1. First item will come from primary iterator
  2. Two items from secondary iterator
  3. One item from primary iterator
  4. Go back to step 2 until one of iterator return None

If a = 2, b = -1 then

  1. First item will come from secondary iterator
  2. Two items from primary iterator
  3. One item from secondary iterator
  4. Go back to step 2 until one of iterator return None

If a = -2, b = -1 then

  1. First item will come from secondaary iterator
  2. Two items from secondary iterator
  3. One item from primary iterator
  4. Go back to step 2 until one of iterator return None

If a = 2, b = 0 then

  1. Two items from primary iterator
  2. One item from secondary iterator
  3. Go back to step 1 until one of iterator return None

If a = 0, b = 3 then iterator will yield only three items from primary iterator. The result will be similar to primary.take(3) iterator but less efficient.

Implementations

impl<I, J, T> LinearCorIter<I, J, T> where
    I: Iterator,
    J: Iterator,
    T: PrimInt
[src]

pub fn new(primary: I, secondary: J, a: T, b: T) -> LinearCorIter<I, J, T>

Important traits for LinearCorIter<I, J, T>

impl<I, J, T> Iterator for LinearCorIter<I, J, T> where
    I: Iterator,
    J: Iterator,
    T: PrimInt
type Item = Either<I::Item, J::Item>;
[src]

Trait Implementations

impl<I: Debug, J: Debug, T: Debug> Debug for LinearCorIter<I, J, T> where
    I: Iterator,
    J: Iterator,
    T: PrimInt
[src]

impl<I, J, T> Iterator for LinearCorIter<I, J, T> where
    I: Iterator,
    J: Iterator,
    T: PrimInt
[src]

type Item = Either<I::Item, J::Item>

The type of the elements being iterated over.

Auto Trait Implementations

impl<I, J, T> RefUnwindSafe for LinearCorIter<I, J, T> where
    I: RefUnwindSafe,
    J: RefUnwindSafe,
    T: RefUnwindSafe

impl<I, J, T> Send for LinearCorIter<I, J, T> where
    I: Send,
    J: Send,
    T: Send

impl<I, J, T> Sync for LinearCorIter<I, J, T> where
    I: Sync,
    J: Sync,
    T: Sync

impl<I, J, T> Unpin for LinearCorIter<I, J, T> where
    I: Unpin,
    J: Unpin,
    T: Unpin

impl<I, J, T> UnwindSafe for LinearCorIter<I, J, T> where
    I: UnwindSafe,
    J: UnwindSafe,
    T: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Correlate for T where
    T: IntoIterator
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<I> IntoIterator for I where
    I: Iterator
[src]

type Item = <I as Iterator>::Item

The type of the elements being iterated over.

type IntoIter = I

Which kind of iterator are we turning this into?

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.