What is the pivot() method in Euphoria?
Overview
As the name implies, the pivot() method targets a value and carries out computations and operations around this particular value, giving it pivotal attention. This is a simple breakdown of what this method means.
More technically, the pivot() method in Euphoria is built into the sequence.e module of the standard library. It takes in a pivot_value and splits another value from the source when the pivot_value is found in the source, producing three sets of subsequence.
The three subsequence sets are:
- Values in the
sourceless than thepivot_value. - Values that are equal to the
pivot_valuein thesource. - Values that are greater than the
pivotvalue.
Syntax
pivot(source, pivot_value)
Parameters
-
source: Thesourceis an object-type variable, which will be split around a pivot. -
pivot_value: This can be an integer or a sequence. It will serve as the point in thesourceat which the split will occur.
Return value
It will return a sequence with three subsequences, as explained below.
-
In the first subsequence, values in the
sourceare less than thepivot_value. -
The second subsequence contains values equal to the
pivot_valuein thesource. -
The third subsequence contains values greater than the
pivot_valuein thesource.
Example
--include the neccessary moduleinclude std/sequence.e--declare a variablesequence output--save the outcome of using pivot methodoutput = pivot( {12, 4, 6.7, 9, 9, -3.8, 9, 14, 3.341, -8}, 9 )--print the outcome to screenprint(1,output)
Explanation
- Line 3: We include the
sequence.emodule. - Line 5: We declare the sequence output.
- Line 7: We save the outcome of using the
pivot()method in the output variable. - Line 9: We print the result to screen.