Skip to content

Commit

Permalink
Better vararg handling
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffgbutler committed May 1, 2024
1 parent 07cb132 commit 15d258e
Showing 1 changed file with 4 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,24 +65,14 @@ class KSimpleCaseDSL<T : Any> : KElseDSL {
}
internal val whenConditions = mutableListOf<SimpleCaseWhenCondition<T>>()

fun `when`(firstCondition: VisitableCondition<T>, vararg subsequentConditions: VisitableCondition<T>) =
fun `when`(vararg conditions: VisitableCondition<T>) =
SimpleCaseThenGatherer { thenValue ->
val allConditions = buildList {
add(firstCondition)
addAll(subsequentConditions)
}

whenConditions.add(ConditionBasedWhenCondition(allConditions, thenValue))
whenConditions.add(ConditionBasedWhenCondition(conditions.asList(), thenValue))
}

fun `when`(firstValue: T, vararg subsequentValues: T) =
fun `when`(vararg values: T) =
SimpleCaseThenGatherer { thenValue ->
val allConditions = buildList {
add(firstValue)
addAll(subsequentValues)
}

whenConditions.add(BasicWhenCondition(allConditions, thenValue))
whenConditions.add(BasicWhenCondition(values.asList(), thenValue))
}

override infix fun `else`(column: BasicColumn) {
Expand Down

0 comments on commit 15d258e

Please sign in to comment.