Skip to content

Instantly share code, notes, and snippets.

@Kerollmops
Created August 6, 2018 12:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Kerollmops/5c29b7785d6e94501964ddd9834a0483 to your computer and use it in GitHub Desktop.
Save Kerollmops/5c29b7785d6e94501964ddd9834a0483 to your computer and use it in GitHub Desktop.
The `split_first` function for any iterator
// prefer using IntoIterator ?
fn split_first<T, I>(mut iter: I) -> Option<(T, I)>
where I: Iterator<Item=T>
{
match iter.next() {
Some(first) => Some((first, iter)),
None => None,
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment