Advertisement
Guest User

Untitled

a guest
Sep 25th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Kotlin 0.54 KB | None | 0 0
  1.     fun awesomeFun(text: String): Int? {
  2.         print("$text is awesome.")
  3.         return 1 // result of calculation
  4.     }
  5.  
  6.     fun uglyFun(text: String): Int? {
  7.         print("$text is ugly!")
  8.         return null // result of calculation
  9.     }
  10.  
  11.     fun getOrPut(x: String, handler: (key: String) -> Int?) {
  12.         val result = handler(x)
  13.         print( "We received ${result ?: -1} responses.")
  14.     }
  15.    
  16.     fun someCalculation() {
  17.         var isAwesome = true
  18.         getOrPut("Hey", if (isAwesome) ::awesomeFun else ::uglyFun )
  19.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement