Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- fn c<T>(s: String) -> Box<Fn(Box<Fn(String) -> T>) -> T> {
- Box::new(move |k: Box<Fn(String) -> T>| k(s.clone()))
- }
- fn d<T>(k: &'static Fn(String) -> T) -> Box<Fn(i32) -> T> {
- Box::new(move |i: i32| k(i.to_string()))
- }
- fn s<T>(k: &'static Fn(String) -> T) -> Box<Fn(String) -> T> {
- Box::new(move |st: String| k(st))
- }
- fn sprintf<T>(f: &Fn(&Fn(String) -> String) -> T) -> T {
- f(&|x| format!("integer: {}", x))
- }
- fn append<T, U, V>(
- f: &Fn(&Fn(String) -> T) -> V,
- g: &Fn(&Fn(String) -> U) -> T,
- h: &Fn(String) -> U,
- ) -> V {
- f(&(move |s1: String| {
- g(&(move |s2: String| {
- let v = vec![s1.clone(), s2.clone()];
- let v = <[String]>::concat(&v);
- h(v)
- }))
- }))
- }
- fn main() {
- //let result: &Fn(i32) -> String = sprintf(append(&d, &c, &String::from("foo")));
- // println!("--> {}", result(10));
- }
Add Comment
Please, Sign In to add comment