Created
February 10, 2023 10:07
-
-
Save usbharu/ad7c361bb58dfce486a617932485806d to your computer and use it in GitHub Desktop.
最初だけとか最後だけとかできるwhile
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
fun while2Test(){ | |
var i = 0 | |
while2({i <= 4}){ | |
doAny { | |
println("any $i") | |
i++ | |
} | |
doFirst { | |
println("first $i") | |
} | |
doLast { | |
println("last $i") | |
} | |
} | |
} | |
fun while2(bool:()->Boolean, runBlock:While2.()->Unit){ | |
val while2 = While2() | |
while2.apply(runBlock) | |
if (bool()) { | |
while2.doFirst() | |
while2.doAny() | |
} | |
var isWhileRun = false | |
while (bool()) { | |
while2.doAny() | |
isWhileRun = true | |
} | |
if (isWhileRun) { | |
while2.doAny() | |
while2.doLast() | |
} | |
} | |
class While2{ | |
var doFirst :()->Unit = {} | |
var doLast :()->Unit = {} | |
var doAny :()->Unit = {} | |
fun doFirst(runFirst:()->Unit){ | |
doFirst = runFirst | |
} | |
fun doLast(runLast: () -> Unit){ | |
doLast = runLast | |
} | |
fun doAny(runAny:()->Unit){ | |
doAny = runAny | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment