What you will do
Combine the in operator, logical negation, filter(), and map() into one general pattern. The result contains names that are not yet present in a second list.
How it works
users
.filter(user, !(user.name in registeredNames))
.map(user, user.name)The expression user.name in registeredNames tests membership. The outer ! reverses that result, so the filter keeps only users whose name is absent. The following map() projects names from those objects.
Evaluation step by step
Maya in ['Maya', 'Leo']istrue, then negation makes itfalse.Nora in ['Maya', 'Leo']isfalse, then negation makes ittrue.Leois registered, so the filter removes him.- The projection returns
['Nora'].
This pattern is useful whenever values listed in one collection must be excluded from another collection.
Your task
- Run the prepared expression.
- Remove
!and compare the result. - Add
NoratoregisteredNames.
Expected observation: Without negation, the expression returns registered names. Adding Nora makes the original exclusion result empty.
Common mistake
Do not confuse !(value in list) with !value in list. Parentheses state clearly that the membership result is being negated.
Show the explanation
Membership is evaluated first, and then its boolean result is reversed. Parentheses also make that intention clear to the next reader.
Knowledge check
Why is it useful to filter the objects before map() turns them into names?
Key takeaway
Combining filter() and map() separates the decision about which items survive from the decision about their output shape.
Sources
CEL-DEV— official overview of CEL operators and collection macros.CEL-LANG— official definition ofin, negation, and macros.CEL-GO-BIND— official documentation for the optionalcel.bind()extension used by the self-contained tab.