Skip to content

Commit

Permalink
Update documentation.
Browse files Browse the repository at this point in the history
  • Loading branch information
TheVeryDarkness committed Oct 6, 2024
1 parent bad3b18 commit ed901c6
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,17 +239,25 @@
//!
//! ```rust
//! use iof::{sep_by, SepBy};
//! use std::collections::{BTreeMap, BTreeSet};
//!
//! let v = vec![1, 2, 3];
//! let s = format!("{}", v.sep_by(", "));
//! let s = v.sep_by(", ").to_string();
//! assert_eq!(s, "1, 2, 3");
//!
//! let v = vec![vec![1, 2, 3], vec![4, 5, 6]];
//! let s = sep_by!(v, "\n", ", ");
//! // Above line is equivalent to:
//! // let s = v.map(|e| e.sep_by("\n")).sep_by(" ");
//! let s = format!("{}", s);
//! assert_eq!(s, "1, 2, 3\n4, 5, 6");
//! assert_eq!(s.to_string(), "1, 2, 3\n4, 5, 6");
//!
//! let v = BTreeSet::from_iter([3, 1, 2, 4]);
//! let s = v.sep_by(", ").to_string();
//! assert_eq!(s, "1, 2, 3, 4");
//!
//! let v = BTreeMap::from_iter([(3, "w"), (1, "x"), (2, "y"), (4, "z")]);
//! let s = v.iter().map(|(k, v)| format!("{} -> {}", k, v)).sep_by("\n").to_string();
//! assert_eq!(s, "1 -> x\n2 -> y\n3 -> w\n4 -> z");
//! ```
//!
//! Note that the iterator must implement [Clone] trait to use the [SepBy] trait.
Expand Down

0 comments on commit ed901c6

Please sign in to comment.