Last active
April 23, 2017 03:58
-
-
Save cohama/2cad088c87b56dc82aec0c4ba5a5b0da to your computer and use it in GitHub Desktop.
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
fn main() { | |
println!("{:?}", take_while(&[1, 2, 3, 4, 5], |&x| x < 3)); | |
} | |
fn take_while<T, F>(xs: &[T], f: F) -> &[T] | |
where F: Fn(&T) -> bool | |
{ | |
let mut i = 0; | |
while f(&xs[i]) { | |
i += 1; | |
} | |
&xs[0..i] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment