Skip to content

Instantly share code, notes, and snippets.

@milanpanchal
Created May 7, 2020 10:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save milanpanchal/c03d8d2742a17c6dce785171fd9ce24a to your computer and use it in GitHub Desktop.
Save milanpanchal/c03d8d2742a17c6dce785171fd9ce24a to your computer and use it in GitHub Desktop.
Partial functions allow you to encapsulate one function within another.
import UIKit
func add(x: Int, y: Int, z: Int) -> Int {
return x + y + z
}
func addX(x: Int) -> (Int, Int) -> Int {
func addYAndZ(y: Int, z: Int) -> Int {
return x + y + z
}
return addYAndZ
}
let add5 = addX(x: 5)
add5(6, 7)
let add10 = addX(x: 10)
add10(3, 4)
func addXAndY(x: Int, y: Int) -> (Int) -> Int {
func addZ(z: Int) -> Int {
return x + y + z
}
return addZ
}
let add4And5 = addXAndY(x: 4, y: 5)
add4And5(10)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment