concept function reference in category kotlin

appears as: function reference, Function references, A function reference
The Joy of Kotlin

This is an excerpt from Manning's book The Joy of Kotlin.

Note the use of a function reference in the last line of the groupByCard function. Function references are similar to method references in Java. If this example isn’t clear, well, that’s what this book is for! When you reach the end, you’ll be an expert in composing such code.

Using a function reference simplifies the syntax:

Listing 12.13 The new stack-safe version of Console class
object Console {

    private val br = BufferedReader(InputStreamReader(System.`in`))

    /**
     * A possible implementation of readLine as a val function
     */
    val readLine2: () -> IO<String> = {
        IO.Suspend {
            try {
                br.readLine()
            } catch (e: IOException) {
                throw IllegalStateException(e)
            }
        }
    }

    /**
     * A simpler implementation of readLine. A function reference is not
     * possible due to the name clash. Use different names for fun and val
     * functions if you want to use function references
     */
    val readLine = { readLine() }

    /**
     * A fun version of readLine
     */
    fun readLine(): IO<String> = IO.Suspend {
            try {
                br.readLine()
            } catch (e: IOException) {
                throw IllegalStateException(e)
            }
        }

    /**
     * A vall version of printLine
     */
    val printLine: (String) -> IO<Unit> = { s: Any ->
        IO.Suspend {
            println(s)
        }
    }

    /**
     * A fun version of printLine
     */
    fun printLine(s: Any): IO<Unit> = IO.Suspend { println(s) }

    /**
     * A print function. Note the fully qualified call to kotlin.io.print.
     */
    fun print(s: Any): IO<Unit> = IO.Suspend { kotlin.io.print(s) }
}