map(Loop,x.parameter) or map(List,x.parameter)
This function is a versatile tool in programming that simplifies list manipulation. With map(), you can swiftly apply an operation to every element in a list, creating a new list that holds the results. This function is particularly useful when you want to transform a list's contents without manually iterating through each element. In addition, map() is also used for extracting parameters from a loop, creating a new list with the same length as loop that returns the value of specified parameter for each iteration.
Example1:
<br><O N="mapFunctionObject1" T="Project" Category="Functions" TransAlignRule="1"><br> <!-- created by ParamML Examples on 8/10/2023 --><br> <P N="List1" V="[1,2,3,4,5,6]" /><br> <!-- add +1 to each value in the list --><br> <P N="map1" V="map(List1, x+1)" /><br> <!-- get index number of each item in the list --><br> <P N="map2" V="map(List1, xi)" /><br> <!-- change default counter --><br> <P N="map3" V="map(List1, k=> k+1)" /><br> <!-- create list of list --><br> <P N="map4" V="map(List1, List1)" /><br> <!-- get value of first item in each list in a list of list --><br> <P N="map5" V="map(map4, x[0])" /><br> <!-- usage of map() inside map() --><br> <!-- y represents each list item in the list of list --><br> <P N="map6" V="map(map4, y=>map(y, x-1))" /><br> <!-- manipulation of list count in a list of list --><br> <P N="map7" V="map(map4, y=> filter(y,x.LT.3))" /><br> <!-- extract value from loop --><br> <O N="Loop1" T="Repeat" S="0" E="9" I="1" CTRL="index" index="0"><br> <O N="Line1" T="Line"><br> <O N="PT1" T="Point" X="0" Y="0" Z="0" /><br> <O N="PT2" T="Point" X="10 * index + 1" Y="0" Z="0" /><br> </O><br> </O><br> <!-- extract parameter value --><br> <P N="map8" V="map(Loop1, x.Line1.PT2.X)" /><br> <!-- extract object --><br> <P N="map9" V="map(Loop1, x.Line1.PT2)" /><br></O><br>

The provided ParamML code defines a "Project" object that showcases various parameter manipulation techniques. It initializes a list, performs mappings such as value incrementation and index extraction, generates a list of lists, and applies nested mappings and filtering. Additionally, the code extracts X coordinates and entire point objects from loop iterations. These examples illustrate ParamML's capacity to simplify complex data transformations, rendering it an invaluable tool for parametric modeling and aiding in the comprehension of mapping, manipulation, and object interaction concepts. Also, please keep in mind that utilizing the map() function instead of T="Repeat" object for operations consisting solely of parameters, not objects, will enhance computational performance.
To view this example in the library, see (https://openbrim.org/app/?incubator=1&author=ParamML_Examples_OpenBrIM+Platform&obj=objidhrchfgy1jum2pvuvof91ip )
Last updated