1 stable release

1.0.0 Jul 22, 2021

#1421 in Algorithms

Download history 149/week @ 2024-01-04 39/week @ 2024-01-11 127/week @ 2024-01-18 140/week @ 2024-01-25 315/week @ 2024-02-01 253/week @ 2024-02-08 100/week @ 2024-02-15 188/week @ 2024-02-22 258/week @ 2024-02-29 203/week @ 2024-03-07 186/week @ 2024-03-14 260/week @ 2024-03-21 180/week @ 2024-03-28 116/week @ 2024-04-04 178/week @ 2024-04-11 253/week @ 2024-04-18

738 downloads per month
Used in 2 crates (via polynomen)

GPL-3.0-only

15KB
193 lines

zip-fill - Iterator Library

Repository

Crate registry

Documentation

Zip two iterators, if they have different length, the shortest is extended using a default value.

The two iterators must have the same Item type.

It is similar to zip_longest algorithm from the itertool python library.

Example

use zip_fill::ZipFill;
let a = [ 1, 2, 3, 4];
let b = [ 1, 2];
let z: Vec<_> = a.iter().zip_longest(&b, &0).collect();
assert_eq!(vec!((&1, &1), (&2, &2), (&3, &0), (&4, &0)), z);
let z: Vec<_> = zip_fill::zip_longest_with(&a, &b, &0, |a, b| a + b).collect();
assert_eq!(vec!(2, 4, 3, 4), z);

Requirements

Minimum tested rustc version: 1.44


lib.rs:

Iterator extensions

Zip two iterators, if they have different length, the shortest is extended using a default value.

The two iterators must have the same Item type.

It is similar to zip_longest algorithm from the itertool python library.

Example

use zip_fill::ZipFill;
let a = [ 1, 2, 3, 4];
let b = [ 1, 2];
let z: Vec<_> = a.iter().zip_longest(&b, &0).collect();
assert_eq!(vec!((&1, &1), (&2, &2), (&3, &0), (&4, &0)), z);
let z: Vec<_> = zip_fill::zip_longest_with(&a, &b, &0, |a, b| a + b).collect();
assert_eq!(vec!(2, 4, 3, 4), z);

No runtime deps