splop 0.2.0

Helper functions to determine the first/last repetition of something.
Documentation
  • Coverage
  • 81.25%
    13 out of 16 items documented8 out of 12 items with examples
  • Size
  • Source code size: 30.22 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 2.98 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 12s Average build duration of successful builds.
  • all releases: 12s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • LukasKalbertodt/splop
    4 0 1
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • LukasKalbertodt

Splop

Build Status crates.io version docs

This tiny crate contains functions and types to help you do something special when repeating for the first or last time (or in between!). This crate offers two distinct features:

  • IterStatusExt::with_status: a new method for iterators, that creates a new iterator which yields the item paired with information to tell you if this is the first/last item.
  • SkipFirst: a simple struct to help you always do something, except on the first repetition. Works without iterators, too!

Examples

(also see examples/)

let names = ["anna", "peter", "brigitte", "bob"];

for (name, status) in names.iter().with_status() {
    print!("{}", name);

    if status.is_first() {
        print!(" <-- winner (ᵔᴥᵔ)");
    }
    if status.is_last_only() {
        print!(" ... ʘ︵ʘ");
    }

    println!();
}

The old programming problem – commas in between elements:

let mut comma = SkipFirst::new();

print!("[");
for name in &["banana", "melon", "kiwi"] {
    comma.skip_first(|| print!(", "));
    print!("{}", name);
}

println!("]");

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.