Created
August 6, 2018 12:06
-
-
Save Kerollmops/5c29b7785d6e94501964ddd9834a0483 to your computer and use it in GitHub Desktop.
The `split_first` function for any iterator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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