Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

euphoria
method
communitycreator

What is the mapping() method in Euphoria?

NDUKWE CHIDERA K.

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

What is the 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.

Syntax

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.

Parameter values

  • 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.

Return value

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:

Pictorial representation of how the mapping() method works

include std/sequence.e
printf(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"))
An example of the mapping() method

Explanation

  • Line 2: We import the relevant modules.
  • Lines 3–5: We use the mapping() method and print the output to the screen.

RELATED TAGS

euphoria
method
communitycreator

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring