Advertisement
Guest User

Untitled

a guest
Apr 25th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rust 0.33 KB | None | 0 0
  1. fn compose<X, Y, Z>(a: Box<Fn(Y) -> Z>, b: Box<Fn(X) -> Y>) -> Box<Fn(X) -> Z>
  2.     where X: 'static,
  3.          Y: 'static,
  4.           Z: 'static
  5. {
  6.    Box::new(move |c| a(b(c)))
  7. }
  8.  
  9. fn main() {
  10.    let composed = compose(Box::new(move |num| num - 1), Box::new(move |num| num * 2));
  11.  
  12.    println!("{}", composed(10));
  13.    //=> 19
  14. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement