Skip to content

Instantly share code, notes, and snippets.

@shubhamkumar13
Created May 26, 2024 13:02
Show Gist options
  • Save shubhamkumar13/1cee09cb75c2ae7910a6fa9c7272c279 to your computer and use it in GitHub Desktop.
Save shubhamkumar13/1cee09cb75c2ae7910a6fa9c7272c279 to your computer and use it in GitHub Desktop.
create a range with a custom function
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