Word = smallWord1 + smallWord2 Look for all six letter words which are composed of two concatenated smaller words.


Please give me feedback regarding good coding standards.

import java.io.File
class KataExercise(val wordLength: Int) {
    fun concatenatedWords(): List&lt;String&gt; {
        val searchWords = dictionary
                .filter { it.length == wordLength }
        val result = mutableListOf&lt;String&gt;()
        for (subWord in smallDictionary) {
            val subWordLength = subWord.length
            (smallDictionary)
                    .filter { it.length + subWordLength == wordLength }
                    .map { it + subWord }
                    .filter { it in searchWords }
                    .forEach { result.add(it) }
        }
        return result.toList()
    }
    private val dictionary = File("dict.text").readLines()
            .filter { "'" !in it }
    private val smallDictionary: List&lt;String&gt; = dictionary
            .filter { it.length &lt; wordLength}
}
Reduced mutation

val result = mutableListOf&lt;String&gt;()
for (subWord in smallDictionary) {
    val subWordLength = subWord.length
    (smallDictionary)
        .filter { it.length + subWordLength == wordLength }
        .map { it + subWord }
        .filter { it in searchWords }
        .forEach { result.add(it) }
}
return result.toList()


could be replaced with:

return smallDictionary
    .flatMap { first -&gt; smallDictionary.map { first to it } }
    .filter { it.first.length + it.second.length == wordLength }
    .map { it.first + it.second }
    .filter { it in searchWords }


Optimisation

You could filter the 2 lists so the starting list is only words that start with the same letter as the target word, and the ending list is only words that end with the last letter of the target word, for a large wordlist this in theory could reduce the size of these lists by a large amount.