Skip to content

Instantly share code, notes, and snippets.

@knjname
Last active November 20, 2017 15:18
Show Gist options
  • Save knjname/281a2f1c8dd4067aac1f72fc48313459 to your computer and use it in GitHub Desktop.
Save knjname/281a2f1c8dd4067aac1f72fc48313459 to your computer and use it in GitHub Desktop.
fun main(args: Array<String>) {
var i = 0
until({ i++ >= 100 }, {
println(fizz(i))
if (i == 50) {
return
}
})
}
fun fizz(n: Int): String {
unless(n % 3 == 0) {
return "${n}"
}
return "fizz"
}
inline fun unless (condition: Boolean, then: () -> Unit) {
if (! condition) then.invoke()
}
inline fun until (condition: () -> Boolean, body: () -> Unit) {
while(! condition.invoke() ) body.invoke()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment