concept file in category kotlin
appears as: files, file, file

This is an excerpt from Manning's book The Joy of Kotlin.
Restricting effects (interaction with the outside world) to specific areas in your code. This means no printing to the console or to any device, no writing to files, databases, networks, or whatever else that can happen outside of these restricted areas.
You could write a concrete implementation for this interface, but first you’ll write an abstract one (because you might want to read data from some other source, such as a file). You’ll put the common code in an abstract class and extend it for each type of input. The following listing shows this implementation.
fun get(path: String): String = #1 Random().nextInt(10).let { when { it < 8 -> throw IOException("Error accessing file $path") else -> "content of $path" } } var retries = 0 var result: String? = null (0 .. 3).forEach rt@ { #2 try { result = get("/my/path") return@rt #3 } catch(e: IOException) { if (retries < 3) { Thread.sleep(100) #4 retries += 1 } else { throw e #5 } } } println(result) #1 Simulates a function that throws an exception 80% of the time #2 Used as the parameter of the forEach function; rt@ indicates where you want to return from inside the function #3 As indicated by return@rt, return from inside the function used as the parameter of the forEach function is triggered when the call to get succeeds. #4 If get throws an exception and retries is smaller than 3, a retry is attempted after waiting for 100 ms. #5 If an exception is thrown and retries isn’t smaller than 3, the exception is rethrown.