mapping()
method?The mapping()
method is an inbuilt method in Euphoria. It sets the values found in a set A
that are the same as those found in another set B
to those in a final set C
.
For example, if A
is COUGH
, B
is CHo
, and C
is chy
, then the mapping()
method will give the output cOUGh
. That is how this method works.
mapping(source_arg,from_set,to_set,level)
When elements from source_arg
are found in from_set
, it is changed to a matching element
of to_set
.
source_arg
: This is the Euphoria object variable that will be changed/mapped.
from_set
: This is a sequence of objects that contains items from the source
that will be changed. These items are the ones that are actually transformed.
to_set
: These are the changed forms of items from the source_args
variable, which are found in the from_set
.
level
: This is an integer value parameter, which can be a 0
(the default) or 1
. If the integer value is 0
, then it implies that mapping will be done to every atom in every level of the sub-sequences. And if the integer value is 1
, the mapping will only apply to the items at the first level in source_arg
.
The mapping()
function returns an object value that is a mapped form of the source_arg
variable.
The image given below is a pictorial explanation of all that’s been said so far:
include std/sequence.eprintf(1,"%s", {mapping("COUGH", "CHo", "chy")})printf(1, "\n%s", {mapping("Educative Edpresso", "presso", "PRESS")})printf(1, "\n%s", mapping({"my name is pinky","Hello pinky"}, "yak", "YAK"))
mapping()
method and print the output to the screen.