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
func toPeano(_ n: Int) -> Any { | |
precondition(n >= 0) | |
if n == 0 { | |
return nil as Any? | |
} else { | |
return toPeano(n - 1) as Any? | |
} | |
} | |
protocol OptionalProtocol { |
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
func i(_ condition: Bool, then: () -> ()) -> (() -> ()) -> () { | |
func run(_ condition: Bool) -> (() -> ()) -> () { | |
return { _ = condition && $0() as Any is () } | |
} | |
run(condition)(then) | |
return run(!condition) | |
} | |
// Usage: | |
let els = i(true) { |