Skip to main content
New Participant
Jun 22, 2023 3:29 PM UTC
Question

reject function giving error when all the items in the list are null

reject() function giving error when all the items in the list are null

Example:

reject(fn!isnull, {null(), null(), null()}) --> error

Is this expected or it is a bug?

4 replies

mikes0011
Brainy
Jun 22, 2023 3:54 PM UTC

reject() and the other looping functions are legacy, and don't handle corner cases very well.  Almost all of them can be safely replaced by a!forEach() (sometimes wrapped in a!flatten()).  FWIW, the only legacy function I know of which can't be replaced thus, is reduce().

a!flatten(a!forEach(local!myList, if(a!isNullOrEmpty(fv!item), {}, fv!item)))

The Expression Guru
harshitb6843
Brainy
Jun 22, 2023 5:02 PM UTC

I strongly agree with Mike. Ever since I realized that {} does not get returned in output, I have stopped using reject(). Please bear in mind that if you replace {} with anything in the above expression, then it will not be removed.

sanchitg0002
Inspiring
Jun 22, 2023 4:29 PM UTC

What error do you get?

It works perfectly fine for me

mikes0011
Brainy
Jun 22, 2023 4:33 PM UTC

Yeah, I still get a valid output even if I use OP's exact same original syntax.

The Expression Guru