Advertisement
Guest User

Untitled

a guest
Jul 26th, 2016
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. function wrap<T extends Function>(fn: T) {
  2. return (...args) => {
  3. return fn(...args)
  4. };
  5. }
  6.  
  7. function foo(a: string, b: number): [string, number] {
  8. return [a, b];
  9. }
  10.  
  11. const wrappedFoo = wrap(foo);
  12.  
  13. function wrap<A, B, C>(fn: (a: A, b: B) => C) {
  14. return (a: A, b: B): C => {
  15. return fn(a, b);
  16. };
  17. }
  18.  
  19. const wrappedFoo = wrap(foo);
  20.  
  21. function wrap<In, Out>(fn: (params: In) => Out) {
  22. return (params: In): Out => {
  23. return fn(params);
  24. };
  25. }
  26.  
  27. interface FooParams {
  28. a: string;
  29. b: number;
  30. }
  31.  
  32. function foo(params: FooParams): [string, number] {
  33. return [params.a, params.b];
  34. }
  35.  
  36. const wrappedFoo = wrap(foo);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement