All functions

Appian reject()

Remove the items of a list that pass a test. Takes a function reference rather than a condition, which is the part that catches people out.

Official Appian documentation

The shape

reject() takes a test and a list, and hands back the list with everything that passed the test removed.

reject(fn!isnull, {1, null, 3})   →   {1, 3}

The nulls matched, so the nulls are gone. What is left is what did not match.

It removes. It does not keep.

The name is the whole instruction, and it is the opposite of what most filtering functions do. reject(fn!even, ...) gives you the odd numbers. If you find yourself wanting the items that matched, you either need a test that asks the opposite question, or you need a different tool.

The first argument is a function, not a condition

This is where people get stuck. You cannot write a comparison there:

reject(fv!item > 5, numbers)     ✗ not a function
reject(isnull, numbers)          ✗ missing the fn! prefix
reject(fn!isnull, numbers)       ✓

fn! names an existing function without calling it. reject() then calls it once per item and drops the ones that come back true. fn!isnull, fn!isnullorempty, fn!even, fn!odd and fn!istext are the ones you will reach for most.

Tests that need a second value

When the function takes more than one argument, an underscore marks the slot each item goes into:

reject(fn!startswith(_, "a"), {"apple", "pear", "ant"})   →   {"pear"}

The item lands where the _ is, and everything else is fixed for the whole run. Put the underscore in the other slot when the item is the second argument: fn!contains(bannedList, _) asks whether the block list contains this item.

When it cannot help

The test has to be an existing function. There is no function for "longer than ri!limit" or "score below the average", so reject() cannot express those at all.

That is not a failure of the function, it is its boundary. For a condition you have to write yourself, loop instead and return {} for the items you are dropping:

a!forEach(items: scores, expression: if(fv!item < 50, {}, fv!item))

Use reject() when a function already says what you mean. It is shorter, and it says it in one line.

Try it

Run each one and read what comes back before moving on.

1The one you will write most often: drop the nulls out of a list.

reject(fn!isnull, {1, null, 3})

2Now leave the fn! prefix off and see what happens.

reject(isnull, {1, null, 3})

Ask it to reject the even numbers, and read the result carefully.

reject(fn!even, {1, 2, 3, 4, 5})

A test that needs a second value. The underscore marks where each item goes.

reject(fn!startswith(_, "a"), {"apple", "pear", "ant"})

isnullorempty catches empty text as well as null.

reject(fn!isnullorempty, {"a", "", null, "b"})

Give it a list where nothing matches.

reject(fn!isnull, {1, 2, 3})

Independent evaluator — approximates the Appian expression language and may differ from a real Appian environment. Verify anything that matters. Terms

Exercises

0 of 5 cleared
  1. 1reject(): drop the nulls from a list
  2. 2reject(): drop blanks as well as nulls
  3. 3reject(): apply an odd-even driving rule
  4. 4reject(): drop internal accounts from a report
  5. 5reject(): clean a phone list before a text campaign
Start the first exercise