Skip to content

Instantly share code, notes, and snippets.

@thomaslee
Created May 29, 2013 07:07
Show Gist options
  • Save thomaslee/5668463 to your computer and use it in GitHub Desktop.
Save thomaslee/5668463 to your computer and use it in GitHub Desktop.
Ick. :)
fn main() {
let mut input = str::to_chars("abcd");
while !input.is_empty() {
let pair = taken(input, 2);
input = dropn(input, 2);
io::println(str::from_chars(pair));
}
}
fn taken<T:Copy>(v: &[T], n: uint) -> ~[T] {
v.slice(0, n).to_owned()
}
fn dropn<T:Copy>(v: &[T], n: uint) -> ~[T] {
v.slice(n, v.len()).to_owned()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment