Created
October 18, 2015 05:32
-
-
Save antsmartian/8a52bd9093f95cbb3fe0 to your computer and use it in GitHub Desktop.
Closures in swift
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
//: Playground - noun: a place where people can play | |
import Foundation | |
func tablesOfTwo(x: Int) -> Int { | |
return 2 * x; | |
} | |
func tablesOfThree(x: Int) -> Int { | |
return 3 * x; | |
} | |
tablesOfTwo(3) | |
tablesOfThree(4) | |
func genericTables (x: Int) -> (Int) -> Int { | |
// func innerFuncion(y : Int) -> Int { | |
// return x * y; | |
// } | |
return { y in x * y } | |
// return innerFuncion; | |
} | |
var tablesOfTwoF = genericTables(2) | |
tablesOfTwoF(3) | |
var tablesOfThreeF = genericTables(3) | |
tablesOfThreeF(4) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment