Created
May 7, 2020 10:27
-
-
Save milanpanchal/c03d8d2742a17c6dce785171fd9ce24a to your computer and use it in GitHub Desktop.
Partial functions allow you to encapsulate one function within another.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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