The columnize()
method in Euphoria is inbuilt and part of the sequence.e
module. It can be used to create a table-like column structure from a sequence variable with substrings.
Each corresponding value from all sub-strings in a sequence are grouped into one single sequence. For example, the columnized value of seq1 = {{1,2,3},{4,5,6},{7,8,9}}
will be {{1,4,7},{2,5,8},{3,6,9}
public function columnize(source, cols, defval)
source
: This is a sequence variable, whose value will be columnized. It is usually a sequence value with other sub-sequences inside it.
cols
: This specifies the column we want to return. It can be a range indicated by a set of numbers. For example, if we want the first and second columns from the source
returned, the parameter cols
should be: {1,2}
. But if only the first column is to be returned, it should be 1
.
defval
: This is the value that will be used when a value is not provided for a column in the source
. It is of the object data type and by default 0
which returns all columns.
This method returns a converted form of the sequence source
whose set of sub sequences are converted into columns.
In the code snippet below, the subsequence of a sequence are converted into columns using the columnize()
method. A default value of 10
is used for the column with no value. The target column is the third (3
) column.
include std/sequence.esequence source = {{1,2},{3,4,6},{7,8,9}}object cols = 3object defval = 0sequence resultresult = columnize(source, cols ,defval)print(1,result)
sequence.e
module which has the columnize
method.Lines 3 to 5: We declare and assign values to some variables.
Lines 6 and 7: We declare the result
variable and store the outcome of the columnize()
method in the result
, respectively.
Line 8: We print the content of the result
variable to screen.