to_set() function #45
Replies: 3 comments 15 replies
-
That makes me think that we may want something like |
Beta Was this translation helpful? Give feedback.
-
I think functions prefixed with Your suggestion makes me think of a larger use case. Maybe this particular use case could be addressed with a
To address other use cases, such as sorting in reverse order, maybe the |
Beta Was this translation helpful? Give feedback.
-
I'd just call this |
Beta Was this translation helpful? Give feedback.
-
We need a mechanism to reduce an array to its unique elements.
The proposed function signature would be
array to_set(array arg)
.The first occurrence of each element will be kept in the order it is encountered. Elements are compared with each types equivalence logic.
example:
search([1,1,2,1,4], to_set(@))
->[1,2,4]
search(["a", {"a":1}, {"a":1, "b":2}, [1],{"a":1}, 3, [2]], to_set(@))
->[["a", {"a":1}, {"a":1, "b":2}, [1], 3, [2]]
I chose "to_set" to be consistent with the other "to_*" functions, but this could alternately be named "unique()" or "deduplicate()".
Beta Was this translation helpful? Give feedback.
All reactions