concept application in category kotlin

appears as: application, pplication, pplications, n application
The Joy of Kotlin

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

  • It will never throw any kind of exception. It might throw errors, such as out-of-memory errors (OOMEs) or stack-overflow errors (SOEs), but these errors mean that the code has a bug. This isn’t a situation either you, as a programmer, or the users of your API are supposed to handle (besides crashing the application, which often won’t happen automatically, and eventually fixing the bug).
  • fun <T> readXmlFile(
            sPath: () -> FilePath,    #1  
            sRootName: () -> ElementName,
            function: (Element) -> T,    #2  
            effect: (List<T>) -> Unit): () -> Unit {    #3  
        val path = sPath().value
        val rDoc = path.flatMap(::readFile2String)
        val rRoot = sRootName().value
        val result = rDoc.flatMap { doc ->
            rRoot.flatMap { rootElementName ->
                readDocument(rootElementName, doc) }
                    .map { list -> list.map(function) }    #4  
        }
        return {
            result.forEach(onSuccess = { effect(it) },
                    onFailure = { throw it })
        }
    }
    
    #1   The function is made generic.
    #2   The Pair<String, List<String>> format argument has disappeared, and a new function argument replaces it. This is the function that will be applied to convert the list of elements to a list of T.
    #3   The effect to be applied is now parameterized by List<T>.
    #4   The toStringList and processElement functions have been removed. They’re replaced with an application of the received function.