Advertisement
Guest User

Untitled

a guest
Oct 2nd, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 0.74 KB | None | 0 0
  1. func curry<A, B, R>(_ f: @escaping (A, B) -> R) -> (A) -> (B) -> R {
  2.     return { a in
  3.         { b in
  4.             f(a, b)
  5.         }
  6.     }
  7. }
  8.  
  9. func curry<A, B, C, R>(_ f: @escaping (A, B, C) -> R) -> (A) -> (B) -> (C) -> R {
  10.     return { a in
  11.         { b in
  12.             { c in
  13.                 f(a, b, c)
  14.             }
  15.         }
  16.     }
  17. }
  18.  
  19. struct User {
  20.    
  21.     static let create = curry(User.init(id:name:))
  22.    
  23.     let id: Int
  24.     let name: String
  25.     let email: String?
  26.    
  27.     init(id: Int, name: String, email: String?) {
  28.         self.id = id
  29.         self.name = name
  30.         self.email = email
  31.     }
  32.    
  33.     init(id: Int, name: String) {
  34.         self.init(id: id, name: name, email: nil)
  35.     }
  36. }
  37.  
  38. type(of: User.create)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement