Created
January 28, 2026 14:37
-
-
Save SteGriff/3c3a5c66e234de1c4529d583eeedc00c to your computer and use it in GitHub Desktop.
Kotlin playground
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
| import java.time.LocalDate | |
| fun main(){ | |
| // Currying and function types | |
| val sum = {a : Int, b : Int -> a + b} | |
| fun add(a: Int, b: Int) = a + b | |
| val add2 = {a : Int -> sum(a,2)} | |
| println(sum(2,2)) | |
| println(add2(3)) | |
| println(add(3,3)) | |
| // Extension with trailing lambda | |
| fun String.sentenceCase() : String = this.lowercase().replaceFirstChar { it.uppercase() } | |
| val dayOfWeek = LocalDate.now().dayOfWeek.toString() | |
| val slogan = "BUGS ROCK" | |
| println("${slogan.sentenceCase()} on a ${dayOfWeek.sentenceCase()}") | |
| // Higher order function | |
| fun caser(arg: String, op: (String) -> String) = op(arg) | |
| val result = caser(slogan, String::sentenceCase) | |
| println(result) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment