Should I keep these statements separate and leave ...
# codingconventions
e
Should I keep these statements separate and leave in the type declaration for readability or smush them together? My goal is to write code that is both idiomatic and maintainable.
Copy code
private fun chooseBestMatch(results: List<String>) {
        val lowers = results.map { it.toLowerCase() }
        val matches: List<IntentMatcherResult> = lowers.map { result -> matchers.map { it.matchTranscript(result) } }.flatten().flatten()
        val best = matches.maxBy { it.score }
    }
m
.map { XXX }.flatten()
->
.flatMap { XXX }
.map { it.map { XXX } }.flatten().flatten()
->
.flatMap { it.flatMap { XXX } }
1
👍 2
e
Thanks! It’s now
Copy code
private fun findBestMatch(results: List<String>): IntentMatcherResult? =
        results.map { it.toLowerCase() }
            .flatMap { result ->
                matchers.flatMap {
                    it.matchTranscript(result)
                }
            }
            .maxBy { it.score }
j
Seeing as you only have one input parameter over which you operate, I'd define the function as an extension method