Guest User

Untitled

a guest
Oct 11th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.31 KB | None | 0 0
  1. fn compose<P,R0,R1,F0,F1,FR>(mut f0:F0,mut f1:F1)->FR
  2. where
  3. F0:FnMut(P)->R0,
  4. F1:FnMut(R0)->R1,
  5. FR:FnMut(P)->R1,
  6. {
  7. move|x|{
  8. let x=f0(x);
  9. f1(x)
  10. }
  11. }
  12. fn main(){
  13. let mut func=compose(|x|x+2,|x|x*2);
  14. assert_eq!(4,func(0));
  15. assert_eq!(6,func(1));
  16. assert_eq!(8,func(2));
  17. }
Add Comment
Please, Sign In to add comment