a!map(): pair two lists into records
Medium
Given a list of names and a matching list of scores, return one record per person with a name field and a score field.
{"Ann", "Bo"} and {90, 40} give {a!map(name: "Ann", score: 90), a!map(name: "Bo", score: 40)}.
The two lists line up by position, so loop over the positions rather than over either list.
Inputs
ri!names: List of Textri!scores: List of Integer
ri! Rule Inputs
ri!namesList of Text{
"Ann",
"Bo"
}ri!scoresList of Integer{
90,
40
}Example 1: Two people
Input: ri!names
{
"Ann",
"Bo"
}Input: ri!scores
{
90,
40
}Expected output:
{
a!map(name: "Ann", score: 90),
a!map(name: "Bo", score: 40)
}Example 2: One person
Input: ri!names
{"Cy"}Input: ri!scores
{70}Expected output:
{a!map(name: "Cy", score: 70)}Example 3: Nobody
Input: ri!names
{}Input: ri!scores
{}Expected output:
{}Example 4: Three people keep their order
Input: ri!names
{
"A",
"B",
"C"
}Input: ri!scores
{
1,
2,
3
}Expected output:
{
a!map(name: "A", score: 1),
a!map(name: "B", score: 2),
a!map(name: "C", score: 3)
}Appian Expression Tips
- • Use
ri!variableNamefor rule inputs - • Use
a!localVariables(local!x: …, body)for locals - • Use
a!forEach(items: …, expression: fv!item)to iterate - • Use
where()/reject(fn!isnull, list)to filter