Make Academy Intermediate: Variables in get() and map()

What are you trying to achieve?

Working on course 2 unit 4 and trying to figure out the rationale for variable values (set multiple variables)

Steps taken so far

I have a scenario runnning using get() and map() but why does the exercise want you to map as follows: {{get(map(10.books; “book_title”; “genre”; “Action”); 1)}}

To clarify: why do we have to enter the “book_title”, “genre” etc as text rather than the approach for 10.books?

Screenshots: scenario setup, module configuration, errors

Welcome to the Make community!

The map function works this way:

Let’s take your example:

{{ map(10.books; "book_title"; "genre"; "Action") }}

This is the equivalent of saying:

  1. For the array 10.books,
  2. I want to get only the book_title value of each book,
  3. Where the genre is equal to Action (case-sensitive)

so now you have an array of only book titles.

You could stop here, and don’t really need to “split” them into separate variables like “ActionBookRequest1st” etc., but I think this tutorial is teaching you how to reference individual items from the map function/array.

Hope this helps! Let me know if there are any further questions or issues.

For more information on map and get, see “Mapping with arrays” below:

Here are some useful links and guides you can use to learn more on how to use the Make platform, apps, and app modules. I found these useful when I was learning Make, and hope they might benefit you too —

Getting Started

Help Centre Basics

Articles & Videos

Partner & Custom Apps

@samliew

Thanks Sam, however, one thing that puzzles me is why I have to type the text “book_title” instead of selecting it and thus avoiding typos? — it is basically putting in quotes what can actually be selected (and so appear as a coloured box).

As an aside, one can imagine spelling of colour/color causing issues since if does not match the arrays then there will be an error — so selection will avoid those issues rather than typing the choices.

After all, we do map 10.books by selecting it from the array. Do you get my point on where I am confused?

As a reference here is an example attached to illustrate my confusion: why can’t I select these instead of typing them out?

This is because by mapping a variable into fields in a module, it is going to be replaced with the actual VALUE, and not the KEY (name) of the property.

raw variable key’s text: “author”
variable author value: “P.aul”

What we want is the raw text of the KEY’s name (“author”) inserted into the map variable, hence we have to type them in as there is no option to map the variable’s KEY name/text into the module’s field.

If you click on the variable “author” with a background, you are actually mapping VALUE (“P.aul”). The variable will be replaced at runtime into the value that the variable “KEY” contains.

TL;DR: If you click on a variable, you are mapping the value, not the key name.

Hope this helps! Let me know if there are any further questions or issues.

@samliew

3 Likes