Skip to content

Instantly share code, notes, and snippets.

@ben0x539
Created February 26, 2013 20:18
Show Gist options
  • Save ben0x539/5041766 to your computer and use it in GitHub Desktop.
Save ben0x539/5041766 to your computer and use it in GitHub Desktop.
trait InputRange<T> {
pure fn is_empty(&self) -> bool;
pure fn head(&self) -> &self/T;
pure fn tail(&self) -> Self;
}
pure fn each<T, U: InputRange<T>>(range: U, blk: fn(v: &T) -> bool) {
while !range.is_empty() && blk(range.head()) {
range = range.tail();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment