mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
29 lines
459 B
Swift
29 lines
459 B
Swift
// RUN: %target-run-simple-swift | FileCheck %s
|
|
|
|
func double(x: Int) -> Int {
|
|
return x+x
|
|
}
|
|
|
|
func curriedSubtract(x: Int)(_ y: Int) -> Int {
|
|
return x-y
|
|
}
|
|
|
|
func twice(f: (Int) -> Int, x: Int) -> Int {
|
|
return f(f(x))
|
|
}
|
|
|
|
// CHECK: 4
|
|
println(double(2))
|
|
// CHECK: 8
|
|
println(double(4))
|
|
|
|
// CHECK: 12
|
|
println(curriedSubtract(16)(4))
|
|
|
|
// CHECK: 20
|
|
println(twice(double, 5))
|
|
// CHECK: 7
|
|
println(twice({ $0 + 1 }, 5))
|
|
// CHECK: 3
|
|
println(twice({ x in x - 1 }, 5))
|