Skip to content

Instantly share code, notes, and snippets.

@Teino1978-Corp
Forked from antsmartian/currying.swift
Created October 30, 2015 19:02
Show Gist options
  • Save Teino1978-Corp/c96b620f7db80778aab6 to your computer and use it in GitHub Desktop.
Save Teino1978-Corp/c96b620f7db80778aab6 to your computer and use it in GitHub Desktop.
Currying
//: 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)
func genericTablesCurrying (x: Int)(y: Int) -> Int {
return x * y;
}
var tableOfTwoCurring = genericTablesCurrying(2)
tableOfTwoCurring(y: 2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment