Skip to content

Instantly share code, notes, and snippets.

@fromkk
Last active August 31, 2016 00:52
Show Gist options
  • Save fromkk/6f58e87180c7cd5d6951f0b6f23c4385 to your computer and use it in GitHub Desktop.
Save fromkk/6f58e87180c7cd5d6951f0b6f23c4385 to your computer and use it in GitHub Desktop.
.@codelynx1 さんの発表を参考にif文とwhile文を日本語で作ってみた。これは闇が深そうだ。。 #iOSDCRC #CodePiece
import Foundation
//Swift 2.2
public func もし(val: Bool, @noescape _ closure: () -> Void) -> Void {
if val {
closure()
}
}
public func 間(@autoclosure check: (Void) -> Bool, @noescape _ closure: () -> Void) -> Void {
while (check()) {
closure()
}
}
もし(true) {
print("OK")
}
var loop = 0
間 (loop < 10) {
loop += 1
print (loop)
}
//Swift 3
public func もし(_ val: Bool, _ closure: @noescape () -> Void) -> Void {
if val {
closure()
}
}
public func 間( _ check: @autoclosure (Void) -> Bool, _ closure: @noescape () -> Void) -> Void {
while (check()) {
closure()
}
}
もし(true) {
print("OK")
}
var loop = 0
間 (loop < 10) {
loop += 1
print (loop)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment