Skip to content

Commit

Permalink
Use joinTo on StringBuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
krzema12 committed Jan 10, 2025
1 parent 5f9df85 commit c7cafc0
Showing 1 changed file with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ abstract class ConvertCommonTestResourcesToKotlin @Inject constructor(
}

private fun generateFunctions(map: Map<String, Any>, stringBuilder: StringBuilder, path: String = "") {
stringBuilder.appendLine(generateSingleFunction(map, path))
stringBuilder.generateSingleFunction(map, path)
stringBuilder.appendLine()
for ((key, value) in map) {
when (value) {
Expand All @@ -89,12 +89,13 @@ abstract class ConvertCommonTestResourcesToKotlin @Inject constructor(
}
}

private fun generateSingleFunction(map: Map<String, Any>, path: String): String {
private fun StringBuilder.generateSingleFunction(map: Map<String, Any>, path: String) {
val functionName = getFunctionName(path)
return map.entries.joinToString(
map.entries.joinTo(
this,
separator = ",\n",
prefix = "fun ${functionName}() = mapOf(\n",
postfix = "\n)",
postfix = "\n)\n",
) { (key, _) ->
"\"$key\" to ${getFunctionName("$path/$key")}()"
}
Expand Down

0 comments on commit c7cafc0

Please sign in to comment.