July 2018
Intermediate to advanced
400 pages
12h 14m
English
Your random extension is marked with the private visibility modifier:
private fun <T> Iterable<T>.random(): T = this.shuffled().first()
Marking an extension as private prohibits use of the extension outside of the file it is defined in. Right now, the extension you defined is only used in Tavern.kt, so it makes sense to mark it private to restrict access. The rule of thumb is the same for extensions as it is for functions: If the extension will not be used elsewhere, mark it private.
Having said that, you also defined your random extension so that it would work with any Iterable. Are there other places in your code, outside of Tavern.kt, where you could put it to use? As it turns out, there is one. ...
Read now
Unlock full access