Created
May 26, 2024 13:02
-
-
Save shubhamkumar13/1cee09cb75c2ae7910a6fa9c7272c279 to your computer and use it in GitHub Desktop.
create a range with a custom function
This file contains hidden or 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 range(start: isize, stop: isize, fun : impl Fn(&isize) -> isize) -> Vec<isize> { | |
let mut v = vec![start]; | |
let mut temp = start; | |
loop { | |
temp = fun(&temp); | |
v.push(temp.clone()); | |
if temp < stop { | |
break; | |
} | |
} | |
v | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment