Skip to content

Stlnss/Basic-Codelab

Repository files navigation

Basic-Codelab

■screen shot

Untitled

■reference

■partical kotlin training

// Use function types and lambda expressions in Kotlin
import kotlinx.coroutines.*


fun main() {
    val treatFunction = trickOrTreat(isTrick = false){ "Have $it quarters!" }
    val trickFunction = trickOrTreat(isTrick = true, extraTreat = null)
    treatFunction()
    repeat(4) {
    	trickFunction()
    }
}

val trick = {
    println("No treats!")
}
val treat: () -> Unit = {
    println("Have a treat!")
}

fun trickOrTreat(isTrick: Boolean, extraTreat: ((Int) -> String)? ): () -> Unit {
    if(isTrick) {
        return trick
    } else {
        if(extraTreat != null) {
        	println(extraTreat(5))
        }
        return treat
    }
}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages