Skip to content

Instantly share code, notes, and snippets.

@islandjoe
Created May 31, 2018 15:09
Show Gist options
  • Save islandjoe/51ac2820f6f580067f3b825fc5980c40 to your computer and use it in GitHub Desktop.
Save islandjoe/51ac2820f6f580067f3b825fc5980c40 to your computer and use it in GitHub Desktop.
Partial application in Swift
func add(x: Int, y: Int, z: Int) -> Int {
  return x + y + z
}

let sum = add(x: 1, y: 2, z: 3)
print(sum)
//-> 6

func addX(_ x: Int) -> (Int, Int)-> Int {
  func addYZ(_ y: Int, _ z: Int) -> Int {
    return x + y + z
  }
    
  return addYZ
}

let xy = addX(1)
//-> 6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment