Skip to content

Instantly share code, notes, and snippets.

@antsmartian
Created October 18, 2015 05:32
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 antsmartian/8a52bd9093f95cbb3fe0 to your computer and use it in GitHub Desktop.
Save antsmartian/8a52bd9093f95cbb3fe0 to your computer and use it in GitHub Desktop.
Closures in swift
//: 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