Synopsis
Returns the item that meets your search criteria from a
list
. In its simplest form, it will return the first item from the
list
inList that matches item. It is more useful when you supply a key, which is a function name applied to each entry in inList. If no entry meets the criteria,
NoValue
is returned.
Syntax
find ( item As Any, _
inList As List, _
Optional key As Any ) As Any
Argument |
Type |
Description |
item
|
Any
|
The value that must be matched for a successful search. |
inList |
List
|
List
of candidates. Only the first one to match will be returned. |
Optional Arguments
Name |
Type |
Default Value |
Description |
key
|
Any
|
Identity
|
Optional; the name of the function applied to each entry in inList prior to comparison; default is :Identity. |
Example 1
Intent >find(3, {1, 2, 3})
--> 3
Example 2
Intent >find(7, {4, 8, 2})
--> NoValue
Example 3
Intent >find(9, {{3, 6, 9}, {9, 5, 6}, {9, 1, 2}}, key := :first)
--> { 9, 5, 6}
In this example, item is compared to only the first member of each of the lists in inList. Note that only the first match was returned.
Example 4
Intent >find("mary", {"peter", "paul", "mary"})
--> "mary"
Example 5
Intent >find(3, {{2, "lm"}, {3, "pq"}, {4, "xy"}}, key := :first)
--> {3, "pq"}