Metaoperators
In Sidef we have an interesting set of metaoperators, which provide an easier way of working with arrays and matrices.
Unroll operator
It's a nice metaoperator borrowed from Perl 6, which unrolls two arrays and applies the operator on each two element-wise objects, creating a new array with the results. The operator can be a method or any other valid operator and must be enclosed between » «
or >> <<
.
Internally, the unroll_operator
method is called, which can, also, be implemented in user-defined classes.
Map operator
The array map operator works exactly like the Array.map{}
method, but it's slightly more efficient and easier to write. The map operator must be enclosed between » »
or >> >>
.
Internally, the map_operator
method is called.
Pam operator
The pam operator is kind of a reversed mapping of the array ("pam" is "map" spelled backwards), where the provided argument is used as the first operand to the operator provided. The operator must be enclosed between « «
or << <<
.
Internally, the pam_operator
method is called.
Reduce operator
This metaoperator reduces an array to a single element. The operator needs to be enclosed inside « »
or << >>
.
Internally, the reduce_operator
method is called.
Cross operator
The metaoperator ~X
or ~Xop
crosses two arrays and returns a new one.
Internally, the cross_operator
method is called.
Zip operator
The metaoperator ~Z
or ~Zop
zips two arrays and returns a new one.
Internally, the zip_operator
method is called.
Wise operator
Almost equivalent with the zip metaoperator, it does element-wise folding on two arbitrary nested arrays, where both arrays must have the same structure.
Internally, the wise_operator
method is called.
Scalar operator
The scalar operator applies a given operator to the elements of an arbitrary nested array, where the provided scalar is used as the second operand to the given operator.
Internally, the scalar_operator
method is called.
Reverse scalar operator
The reverse scalar operator uses the given scalar as a first operand to the given operator and is also defined for arbitrary nested arrays.
Internally, the rscalar_operator
method is called.
Last updated