Skip to content

Commit 22c5d8f

Browse files
author
Rafal Kapela
committed
index consts
1 parent 0c9cacd commit 22c5d8f

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

operations-stdlib/src/commonMain/kotlin/array/JoinToString.kt

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@ import operation.StandardLogicOperation
44
import utils.asList
55

66
object JoinToString : StandardLogicOperation {
7+
private const val ELEMENTS_ARG_INDEX = 0
8+
private const val SEPARATOR_ARG_INDEX = 1
9+
private const val PREFIX_ARG_INDEX = 2
10+
private const val POSTFIX_ARG_INDEX = 3
11+
private const val LIMIT_ARG_INDEX = 4
12+
private const val TRUNCATED_ARG_INDEX = 5
13+
714
override fun evaluateLogic(expression: Any?, data: Any?): Any? = expression.asList.toOperationArguments()?.invoke()
815

916
private fun JoinToStringArguments.invoke() =
@@ -12,20 +19,20 @@ object JoinToString : StandardLogicOperation {
1219
private fun List<Any?>.toOperationArguments(): JoinToStringArguments? = kotlin.runCatching {
1320
checkLimitArg()?.let { limit ->
1421
JoinToStringArguments(
15-
elementsToJoin = get(0).asList,
16-
separator = get(1) as String,
17-
prefix = get(2) as String,
18-
postfix = get(3) as String,
22+
elementsToJoin = get(ELEMENTS_ARG_INDEX).asList,
23+
separator = get(SEPARATOR_ARG_INDEX) as String,
24+
prefix = get(PREFIX_ARG_INDEX) as String,
25+
postfix = get(POSTFIX_ARG_INDEX) as String,
1926
limit = limit,
20-
truncated = get(5) as String
27+
truncated = get(TRUNCATED_ARG_INDEX) as String
2128
)
2229
}
2330
}.fold(
2431
onSuccess = { it },
2532
onFailure = { null }
2633
)
2734

28-
private fun List<Any?>.checkLimitArg() = (get(4) as Number).takeIf {
35+
private fun List<Any?>.checkLimitArg() = (get(LIMIT_ARG_INDEX) as Number).takeIf {
2936
it.toDouble() == it.toInt().toDouble()
3037
}?.toInt()
3138
}

0 commit comments

Comments
 (0)