Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- fun awesomeFun(text: String): Int? {
- print("$text is awesome.")
- return 1 // result of calculation
- }
- fun uglyFun(text: String): Int? {
- print("$text is ugly!")
- return null // result of calculation
- }
- fun getOrPut(x: String, handler: (key: String) -> Int?) {
- val result = handler(x)
- print( "We received ${result ?: -1} responses.")
- }
- fun someCalculation() {
- var isAwesome = true
- getOrPut("Hey", if (isAwesome) ::awesomeFun else ::uglyFun )
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement