1 stable release

1.0.0 Jul 22, 2021

#1463 in Algorithms

Download history 129/week @ 2024-03-13 328/week @ 2024-03-20 172/week @ 2024-03-27 119/week @ 2024-04-03 143/week @ 2024-04-10 244/week @ 2024-04-17 211/week @ 2024-04-24 230/week @ 2024-05-01 667/week @ 2024-05-08 263/week @ 2024-05-15 271/week @ 2024-05-22 359/week @ 2024-05-29 368/week @ 2024-06-05 185/week @ 2024-06-12 52/week @ 2024-06-19 83/week @ 2024-06-26

790 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