LogoLogo
User DocsAPI Docsatfinity.swiss
  • 🚀Atfinity: No-Code Process Automation
  • Guides
    • Getting Started
      • Introduction
      • 1. Create Ontologies and Roles
      • 2. Create Information
      • 3. Create and Configure a Document
      • 4. Create a Rule
      • 5. Create a Process
      • 6. Put Live
      • Summary and Next Steps
    • Advanced Topics
      • Extending a Workflow
      • Customizing Names of Cases and Instances
      • Automatically Calculating Information Values
      • Using Built in Integrations
    • Troubleshooting
      • Why is a question not asked?
      • Why is a question asked?
      • The value of my calculated field has a strange format
      • Why is my Proof never asked for?
      • Why is my Rule not executed?
      • Why are some options missing in a dropdown?
      • Case Errors
    • Glossary
      • Case
      • Process
      • Workflow
      • Ontology
      • Instance
      • Role
      • Information
      • Document
      • Document Section
      • Document Template
      • Rules
      • Scheduled Rules
      • Information Types
      • Tab
      • Category
      • Taxonomy
      • Proof
      • RuLa Functions
      • Constants
  • Rule Language (RuLA)
    • ℹ️What is RuLa?
    • Declarations
      • is
      • is with where
      • is all
      • is all with min max
      • Role Choices
    • Expressions
    • Operators
      • Boolean Operators
        • =
        • !=
        • >
        • >=
        • <
        • <=
        • and
        • and then
        • not
        • or
        • or else
        • matches (~=)
      • Date Operators
        • NOW
        • IS_DATE
        • TODAY
        • FORMAT_DATE
        • DAYS
        • WEEKDAYS
        • ADD_DAYS
        • ADD_WEEKDAYS
        • ADD_MONTH
        • ADD_YEARS
        • SUBTRACT_YEARS
        • AFTER
        • DATE_EQUAL
        • DATETIME_EQUAL
        • AFTER_EQUAL
        • BEFORE
        • BEFORE_EQUAL
        • DAYS_AGO
        • MONTHS_AGO
        • YEARS_AGO
      • Known Operators
        • unknown
        • known
        • SNEAKY
        • AVG_OF_ANY
        • LIST_OF_ANY
        • MAX_OF_ANY
        • MIN_OF_ANY
        • SUM_OF_ANY
        • CONCAT_OF_ANY
        • UNION_OF_ANY
        • JOIN_OF_ANY
      • List Operators
        • [ , ] (create)
        • [] (access)
        • in
        • not in
        • contains
        • contains any
        • contains only
        • COUNT
        • SORT
        • CUSTOM_MAX
        • REVERSE
        • FIRST_ELEMENT
        • ALL
        • SOME
        • UNION (or |)
        • SET_DIFFERENCE
        • INTERSECTION
        • MAP
        • FILTER
        • FILTER_FALSE
        • FILTER_UNKNOWN
        • SET
      • Dictionary Operators
        • {} (create)
        • [] (access)
        • in
        • keys()
        • FLATTEN
      • Mathematical Operators
        • + - / *
        • %
        • **
        • //
        • AVG
        • CEIL
        • FLOOR
        • MAX
        • MIN
        • ROUND
        • SUM
        • SUM_PRODUCT
        • SQRT
      • String Operators
        • LEN
        • LOWER
        • UPPER
        • TRIM
        • TRIM_LEFT
        • LEFT
        • RIGHT
        • SLICE
        • REPLACE
        • REPLACE_CHARS
        • format
        • calculated_name
        • CONCAT
        • markdown_table
        • make_filename
        • JOIN
        • uuid
      • Special Operators
        • :=
        • ensure
        • get_attr
        • get_translated_attr
        • has_attr
        • get_properties
        • instances
        • instances_exist
        • is
        • ontology
        • Translate (.$)
        • translate_string
        • roles
        • self
        • name_and_log (debug)
    • Conditional Expressions
      • case
      • if-then-else
      • switch
    • Comments
    • Information about the case
    • Accessing the outcome instance
    • Information about documents
    • Recipes
  • Document XML (ADX)
    • ℹ️What is ADX?
    • ADX Elements
      • Body
      • Text
      • Image
      • Columns
      • Field
      • Checkbox
      • Table
      • Rect
      • Line
      • Space
      • KeepTogether
      • Template
      • Style
      • Page Number
      • QR Code
      • HR Code
    • Jinja Templating
      • Instances
      • Case Meta Information
      • Custom Translations
      • Functions
      • Jinja filters
    • Font support
  • API
    • ℹ️What is the Atfinity API?
    • Generate API Keys
    • API Documentation
    • Calling your APIs within Cases
    • External Data Sources (e.g. CRM)
  • Deploying
    • Deploying on-site
      • Kubernetes
      • Docker Compose
    • Management commands
    • Security Logging
    • LDAP User Backend
    • Single Sign On
  • Integrations
    • Avaloq
    • Worldcheck
  • Releases
    • Release Notes
      • Version 11.x
      • Version 10.x
      • Version 9.x and earlier
    • Release Schedule
Powered by GitBook
On this page
  • Description
  • Example: Double some numbers
  • Example: Get total income

Was this helpful?

  1. Rule Language (RuLA)
  2. Operators
  3. List Operators

MAP

PreviousINTERSECTIONNextFILTER

Last updated 7 months ago

Was this helpful?

Description

MAP is used to perform the same action on each individual value in a list.

That way, it lets you transform a list of values into another list, which comes in especially handy when working with user-provided values like nationalities or sources_of_income.

Map comes in two versions:

  1. A functional version MAP(<list>, <expression with CURRENT>) where the keyword CURRENT inside the will be replaced with the current element of the list.

  2. A method version that you call on the list as <list>.map(<var> => <expression with var>) that can be called directly on the list

For readability, we recommend using the method version whenever you can.

Example: Double some numbers

SUM(
  [1, 2, 3].map(number => number * 2)
)
  • We call map on a list, here the list of numbers [1, 2, 3].

  • The argument within map is the function we use on each element, here number * 2. It takes each number from that array and multiplies it by 2. With each calculation, the variable number is replaced by the next value from the list, until the last value has been dealt with. We chose the name to be number as the variable before =>. We could have also chosen n or x if we would have wanted to.

  • Since a SUM operator encloses the MAP function, the final output will be the added total of all doubled values - in this case: 12.

The calculations step-by-step:

  • 1 * 2 = 2

  • 2 * 2 = 4

  • 3 * 2 = 6

  • The intermediate result of MAP is the new list [2, 4, 6]

  • SUM adds these new values: 2 + 4 + 6 = 12.

Example: Get total income

p is Person
SUM(
  MAP(
    p.sources_of_income, 
    get_attr(CONCAT("income_" , CURRENT))
  )
)

Here we use the functional version:

  1. we assume a user selects the relevant sources of income out of salary, capital_gain, and gifts

  2. the user then fills out the information with predictable keys, like income_salary, income_capital_gain, and income_gifts.

  3. with get_attr, these values are accessed and added up. If a value has no entry from the user, its default will be 0.

The calculations step-by-step:

  • the first argument of MAP is self.sources_of_income.

  • let's say the user has filled out 10,000 under income_salary, 5000 under income_capital_gain, and nothing under income_gifts.

  • the values of the first argument, which MAP will run over in succession, are salary, capital gain, and gifts.

  • in the first iteration, the first argument of MAP, self.sources_of_income, gets the value salary.

  • Next, CURRENT in the second argument takes that value salary from the first argument. CONCAT attaches it to the string "income_".

  • This means the first run of the MAP function looks like this: MAP(self.salary, get_attr(income_salary)

  • Using the values the user has provided, the MAP function will store 10,000 as the first value of its output. MAP then starts its work over on the second value in the list capital gain.

  • Once MAP has run over all values in the list, it’s intermediate output will be [10000, 5000, 0]

  • Since MAP is wrapped in a SUM function, the final output yields 15000.

expression