Skip to content

Instantly share code, notes, and snippets.

@dumindu
Last active September 25, 2016 01:48
Show Gist options
  • Save dumindu/e1423ebf9d8a40a0a0c0 to your computer and use it in GitHub Desktop.
Save dumindu/e1423ebf9d8a40a0a0c0 to your computer and use it in GitHub Desktop.
fn plus_one(a: i32) -> i32 {
a + 1
}
let b = plus_one;
let c = b(5); //6
let b: fn(i32) -> i32 = plus_one; //same, with type inference
let c = b(5); //6
let b = plus_one;
fn plus_two(b: fn(i32) -> i32, x: i32) -> i32 {
b(b(x))
}
println!("{}", plus_two(b, 2)); //4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment