Last active
September 21, 2024 03:16
-
-
Save JavierSolis/20ba763e09b7b9a4fe334d4f11489480 to your computer and use it in GitHub Desktop.
Usa tipos de funciones y expresiones lambda en Kotlin
This file contains hidden or 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
| /** | |
| Excercise : https://developer.android.com/codelabs/basic-android-kotlin-compose-function-types-and-lambda?hl=es-419&continue=https%3A%2F%2Fdeveloper.android.com%2Fcourses%2Fpathways%2Fandroid-basics-compose-unit-2-pathway-1%3Fhl%3Des-419%23codelab-https%3A%2F%2Fdeveloper.android.com%2Fcodelabs%2Fbasic-android-kotlin-compose-function-types-and-lambda#0 | |
| */ | |
| fun main() { | |
| val trickFunction = ::trick | |
| trickFunction() | |
| trickAsVariable() | |
| trickWhitType() | |
| trickWhitParam("Javier Solis") | |
| trickReturnFun()("Javier S.") | |
| trickWhitTwoParam("Javier","Solis") | |
| trickWhitParamBreved("Javier Solis") | |
| trickParamFun({println("Param function $it")})("Javier Solis") | |
| repeat(3){ | |
| println("try, correct and learn!!! x$it") | |
| } | |
| } | |
| fun trick() { | |
| println("No treats!") | |
| } | |
| val trickAsVariable ={ | |
| println("No treats! x2") | |
| } | |
| val trickWhitType:()->Unit ={ | |
| println("No treats! from whit type") | |
| } | |
| val trickWhitParam:(name:String)->Unit = {name-> | |
| println("No treats! from whit param name = $name") | |
| } | |
| fun trickReturnFun():(nameParam:String)->Unit{ | |
| return { name-> println("Name from fun returned $name")} | |
| } | |
| val trickWhitTwoParam:(name:String,secondName:String)->Unit = {name,secondName-> | |
| println("No treats! from whit param name = $name second = $secondName") | |
| } | |
| val trickWhitParamBreved:(name:String)->Unit = { | |
| println("No treats! from whit param name breved = $it") | |
| } | |
| fun trickParamFun(funParam:(nameParam:String)->Unit):(nameParam:String)->Unit{ | |
| return funParam | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment