zip-optional

Crates.iozip-optional
lib.rszip-optional
version0.1.0
sourcesrc
created_at2024-05-13 05:49:52.441064
updated_at2024-05-13 05:49:52.441064
descriptionan iterator type for zipping with an optional iterator
homepage
repository
max_upload_size
id1238004
size5,493
Jorge Hernandez (jhernandezb)

documentation

README

Zip Optional

An iterator type for zipping with an optional iterable.

When the iterable being zipped has no value (i.e. is None), the initial iterable is effectively zipped with std::iter::repeat(None).

# use zip_optional::zip_optional;

let a = vec![1, 2];

let mut zipped = zip_optional(a, None::<Vec<i32>>);
assert_eq!(zipped.next().unwrap(), (1, None));
assert_eq!(zipped.next().unwrap(), (2, None));
assert_eq!(zipped.next(), None);

When the iterable being zipped has a value, the result of a sequence of Some(_) which contains the items in the iterable being zipped with.

# use zip_optional::zip_optional;

let a = vec![1, 2];
let b = Some(vec![1, 2]);

let mut zipped = zip_optional(a, b);
assert_eq!(zipped.next().unwrap(), (1, Some(1)));
assert_eq!(zipped.next().unwrap(), (2, Some(2)));
assert_eq!(zipped.next(), None);

The provided iterator may also be used inline with other iteration methods, like so:

# use zip_optional::Zippable;

let mut zipped = vec![1, 2].into_iter().zip_optional(Some(vec![1, 2]));
assert_eq!(zipped.next().unwrap(), (1, Some(1)));
assert_eq!(zipped.next().unwrap(), (2, Some(2)));
assert_eq!(zipped.next(), None);
Commit count: 0

cargo fmt