Some Useful User Defined Functions

Courtesy of @kyung.

Arrays#Append

FLAT([ array, [ element ] ])[?(@ <> NULL)]

Arrays#Combine

FLAT([ array, array_2 ])[?(@ <> NULL)]

Arrays#IsValid

LENGTH(array[?(ISNOTEMPTY(@))]) = LENGTH(array)
  AND LENGTH(array[?(ISNOTEMPTY(@))]) > 0

Arrays#DeleteItem

FROM
  p,
  idx
IN
  array
WHERE
  NOT(
    index = idx
  )
SELECT
  p

Objects#Set (Edited per comments)

MERGE_OBJECTS(
  [ obj, { "{{key}}": value } ]
)

Objects#Remove

FROM
  p
IN
  KEYS(
    obj
  )
WHERE
  NOT(
    CONTAINS(
      FLAT(
        [ keys ]
      ),
      p
    )
  )
SELECT
  "{{p}}": obj[p]

6 Likes

:exploding_head: as usual. These are really useful!

1 Like

Thank you for these!!

1 Like

One note, Object#Set needs a minor change:

MERGE_OBJECTS(
  [ obj, { "{{key}}": value } ]
)

Ran into an issue when testing it. :slightly_smiling_face:

1 Like