Skip to content

Instantly share code, notes, and snippets.

@sumproxy
Created August 1, 2015 11:50
Show Gist options
  • Save sumproxy/3dce80273cfed19ac1d6 to your computer and use it in GitHub Desktop.
Save sumproxy/3dce80273cfed19ac1d6 to your computer and use it in GitHub Desktop.
// A function which takes a closure and returns an `i32`.
fn apply_to_n<F, T>(f: F, t: T) -> T where
// The closure takes an `i32` and returns an `i32`.
F: Fn(T) -> T {
f(t)
}
fn main() {
let double = |x| 2 * x;
println!("2 quintupled: {}", apply_to_n::<Fn, i32>(double, 5)); // problem is probably with std::ops::Fn
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment