IMAM00

higher_order_function_day_6

Mar 26th, 2022 (edited)
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Kotlin 0.93 KB | None | 0 0
  1. // ********example via String
  2. fun main() {
  3. myFunction("Hi",::justShow)
  4. }
  5.  
  6. fun myFunction(name:String, myFunc:(String)->Unit){ // must be ->, because differ from regular function declaration
  7. println("It is an example of higher order function")
  8. }
  9. fun justShow(firstName:String):Unit{
  10. }
  11.  
  12. //************same but more details
  13. fun main() {
  14.     myFunction("Hi",::justShow)
  15. }
  16.  
  17. fun myFunction(name:String, myFunc:(String)->Unit){ // must be ->, because differ from regular function declaration
  18.     println("$name, It is an example of higher order function")
  19.     justShow("Now")
  20. }
  21. fun justShow(firstName:String):Unit{
  22.     println("$firstName, It's my call")
  23. }
  24.  
  25.  
  26. // ********example via Int
  27. fun main() {
  28. myFunction(5,::justShow)
  29. }
  30.  
  31. fun myFunction(number: Int,unused:(Int,Int)->Int){
  32.     println(justShow(7,9))
  33.     println("$number")
  34.     println(justShow(72,5))
  35. }
  36. fun justShow(number:Int, firstNumber: Int):Int=number+firstNumber
Add Comment
Please, Sign In to add comment