member()

Synopsis

Returns True if item is in list . The list may contain objects of any type, it does not have to be homogenous.

Syntax

member ( item As Any, _
         list As List, _
         Optional key As Name = :Identity, _
         Optional test As Name = :Equal ) As Boolean 
Argument Type Description
item Any The item to check for list membership. This argument is permitted to be NoValue .
list List A list of items.
key Name Optional; the name of function to be called with each item in the list ; default is :Identity.
test Name Optional; the name of test function to be applied to key results of items in the lists ; default is :Equal.

Example 1

Intent >member(3, {7, 4, 3, 9, 0}) 
--> True 

Example 2

Intent >member(3, {7, 4, 9, 0}) 
--> False 

Example 3

Intent >member(3, {7, 4, 9, 0}, test := :sameType?) 
--> True 
You can also use another function as the test for membership. The default is equal, but you might want to test to based on each member having the same type instead of being equal using the following custom function.
Function sameType?(I As Any, j As Any) As Boolean 
    sameType? = (typeName(i) = typeName(j)) 
End Function 

Example 4

Intent >member(3, {a, b, c, d}, test := :sameType?) 
--> False 
Again, this example uses the custom function shown in the preceding example.

Example 5

Intent >member(2, {"a", "bcd", "ef", "ghi"}, key := :length) 
--> True 
Returned True because one of the members of the list , "ef", has a length of 2.