What is the find_each() method in Euphoria programming?
Introduction
The find_each() method can be found among the numerous search methods in the standard library package.
The find_each method checks two lists of different values. If the values in the second list match either of the values in the first list, then the set of indexes of all such occurrences will be returned as a new resultant list.
For instance, find_each occurrences of the values of A = “piy” in B = “promilitary”. The find_each() method will look for p, i, and y in promilitary and return the index of each occurrence of p, i, and y arranged in ascending other. This will be
{1,5,7,11} as the output. Let’s look at the syntax of this method.
Syntax
find_each(needle_value, haystack_value)
Parameter values
needle_value: This is the list that needs to be searched in thehaystack_value.haystack_value: This is the list that may contain theneedle_valuevalue.
Return value
The find_each() method returns a set of indexes of the found needle_values in the haystack_value. If no needle_values are found, then an empty value is returned.
Code
include std/search.esequence needle_value, haystack_value,outputneedle_value = "org"haystack_value = "pot mould whose plug is sorry"output = find_each(needle_value,haystack_value)print(1, output)
Explanation
-
Line 2: We import
search.e. -
Line 4: We declare some sequence variables.
-
Lines 6 and 8: We assign values to the declared variables.
-
Line 10: We call the
find_each()function to obtain anoutputvariable that contains the list of indexes. -
Line 12: We display all the values present in the
outputvariable on the console.