Skip to content

Commit

Permalink
fix: union() with context entries
Browse files Browse the repository at this point in the history
Remove duplicated context entries from the concatenated list.
  • Loading branch information
saig0 committed Aug 30, 2024
1 parent 1ed648d commit fa45a3d
Showing 1 changed file with 16 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -379,34 +379,31 @@ class ListBuiltinFunctions(private val valueMapper: ValueMapper) {
private def unionFunction = builtinFunction(
params = List("lists"),
invoke = { case List(ValList(lists)) =>
ValList(
lists
.flatMap(_ match {
case ValList(list) => list
case v => List(v)
})
.toList
.distinct
)
val listOfLists = lists.flatMap {
case ValList(list) => list
case v => List(v)
}
ValList(distinct(listOfLists))
},
hasVarArgs = true
)

private def distinctValuesFunction =
builtinFunction(
params = List("list"),
invoke = { case List(ValList(list)) =>
val distinctList = list.foldLeft(List[Val]())((result, item) =>
if (result.exists(y => valueComparator.equals(item, y))) {
// duplicate value
result
} else {
result :+ item
}
)
ValList(distinctList)
invoke = { case List(ValList(list)) => ValList(distinct(list)) }
)

private def distinct(list: List[Val]): List[Val] = {
list.foldLeft(List[Val]())((result, item) =>
if (result.exists(y => valueComparator.equals(item, y))) {
// duplicate value
result
} else {
result :+ item
}
)
}

private def duplicateValuesFunction =
builtinFunction(
Expand Down

0 comments on commit fa45a3d

Please sign in to comment.