mark_last

Crates.iomark_last
lib.rsmark_last
version0.9.2
sourcesrc
created_at2020-12-29 13:18:17.256016
updated_at2020-12-30 17:59:44.650902
descriptionSimple extension to rust iterator's to mark the last element of an iterator
homepage
repositoryhttps://github.com/mrcz/mark_last/
max_upload_size
id328760
size4,332
Marcus Svensson (mrcz)

documentation

README

mark_last

A simple extension to rust iterators which gives the next value as well as a boolean indicating if this is the last value of the iterator.

The iterator returned yields pairs (b, val), where b is true if this is the last value and val is the value returned by the iterator.

Usage

Add mark_last = "0.9.2" to the dependencies section of your Cargo.toml file, and use it like so:

use mark_last::MarkLastIterator;

let in_data = vec![1, 2, 3, 5, 99];

let out_data: Vec<_> = in_data
    .into_iter()
    .mark_last()
    .collect();

assert_eq!(
    out_data,
    vec![
        (false, 1),
        (false, 2),
        (false, 3),
        (false, 5),
        (true, 99)
    ]
)
Commit count: 5

cargo fmt