# Add "iterate with separators" iterator function

**URL:** <https://internals.rust-lang.org/t/add-iterate-with-separators-iterator-function/18781>\
**Category:** libs\
**Created:** [May 4, 2023, 4:59am UTC](https://internals.rust-lang.org/t/add-iterate-with-separators-iterator-function/18781 "2023-05-04T04:59:31Z")\
**Posts on this page:** 1\
**Showing post:** 13

<div class="post-metadata">

**Author:** ![8573](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/8573/32/4913_2.png) [@8573](https://internals.rust-lang.org/u/8573)\
**Post date:** [May 6, 2023, 8:19pm UTC](https://internals.rust-lang.org/t/add-iterate-with-separators-iterator-function/18781/13 "2023-05-06T20:19:01Z")

</div>

This might not be useful more generally, but that `if`-`let`-`else` could be shortened to `print!("{}", v.unwrap_or(&", "))`.

Edited to add: The `for` loop could be

```rust
for v in elements.iter().intersperse(&", ") {
    print!("{v}")
}

```

That seems too simple, so I guess it likely isn't useful.

---

_[View the full topic](https://internals.rust-lang.org/t/add-iterate-with-separators-iterator-function/18781)._
