How to add your knowledge

removeIfNot()

    Table of contents
    1. 1. Synopsis
    2. 2. Syntax
    3. 3. Example 1
    4. 4. Example 2
    5. 5. Example 3

    Synopsis

    Return a copy of the input list, having removed all members for which the function fun returns False.

    Syntax

    removeIfNot ( fun As Name, _
                  list As List ) As Any 
    Argument Type Description
    fun Name The name of the function to apply; the function must return a boolean.
    list List The list of arguments to which the test function will be applied.

    Example 1

    Intent >removeIfNot(:empty?, {{}, {:b}, {}, {:d}}) 
    --> {{}, {}} 
    Returns only empty lists in a list of lists. That is, the non-empty sublists have been removed.

    Example 2

    Using a custom function

    Intent >removeIfNot(string?, {:a, :c, "b", :d, 3, {3}, "3", 2, 1}) 
    --> {"b", "3"} 

    In this example, only non-integers were returned using the following custom function:

    Function string?(item As Any) As Boolean 
        string? = (typeName(item) = :string)
    End Function 

    Example 3

    Intent >removeIfNot(:even?, {1, 2, 3, 4, 5, 6, 7, 8}) 
    --> {2, 4, 6, 8} 
    Here, the odd (not even) items have been removed from the result.