zip-optional 0.1.0

an iterator type for zipping with an optional iterator
Documentation
  • Coverage
  • 10%
    1 out of 10 items documented1 out of 5 items with examples
  • Size
  • Source code size: 5.18 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 2.2 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Links
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • jhernandezb

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);