camunda / feel-scala

FEEL parser and interpreter written in Scala
https://camunda.github.io/feel-scala/
Apache License 2.0
120 stars 50 forks source link

Add new built-in function to find duplicates #642

Closed saig0 closed 1 year ago

saig0 commented 1 year ago

Is your feature request related to a problem? Please describe. Currently, we don't have a direct function that can return us all the duplicates from a list. We managed to use a workaround with the use of list expressions, functions, and control flows. This functionality would be the exact opposite of distinct values().

// repeated_item_list = 
for x in list return if count(list[item = x]) > 1 then x else null
// distinct_repeated_list
distinct values(repeated_item_list[item != null])

Describe the solution you'd like Add a new function to find duplicate values in a list.

Signature:

duplicate values(list: list): list

Examples:

duplicate values([1,2,3,2,1])
// [1, 2]

Related issues

saig0 commented 1 year ago

Workaround

We could use the following expression to find the duplicate values:

distinct values(list[count(index of(list, item)) > 1])
saig0 commented 1 year ago

@aleksander-dytko please prioritize this feature in the context of this support case.

koevskinikola commented 1 year ago

ZPA triage:

abbasadel commented 1 year ago

@saig0 since this is a support case, I think it makes sense to add "support" label so we don't lose track of it.