Whatever message this page gives is out now! Go check it out!

removeIf

Last update:
Jun 9, 2026
Removes all elements that satisfy a predicate.

Description

Removes all elements that satisfy a predicate (callback). Typically, removeIf passes each element to a function or closure; elements for which the predicate returns true are removed from the set in place.

Returns

Void

Category

ColdFusion Set member methods

Function syntax

set.removeIf(predicate)

Parameters

ParameterDescription
predicateFunction or closure; return true to remove the element.

See also

Example

The following example uses this API in cfscript (syntax: set.removeIf(predicate)).

<cfscript>
    s = setNew();
    s.add(1);
    s.add(2);
    s.add(3);
    s.add(4);

    // Hypothetical: remove even numbers
    s.removeIf( (n) => n mod 2 eq 0 );
</cfscript>
      

Real-world example

Drop cache keys whose expiry time is in the past (predicate reads a parallel expiry struct).

<cfscript>
    /**
    * Pseudocode: predicate checks external TTL map.
    * Adjust to your engine's closure/lambda syntax.
    */
    function removeExpiredKeys(required any keySet, required struct ttlByKey, required date now) {
        keySet.removeIf( function(key) {
            if (!structKeyExists(ttlByKey, key)) return true;
            return ttlByKey[key].lt(now);
        });
        return keySet;
    }
</cfscript>
      

Share this page

Was this page helpful?
We're glad. Tell us how this page helped.
We're sorry. Can you tell us what didn't work for you?
Thank you for your feedback. Your response will help improve this page.

On this page