
map
(namely, in the context of ADTs in a project that's already known to be difficult). I think we need a simpler introduction--perhaps in the Sentence Builder content that will be added to the Gossip lab (e.g., plurals using map
). (If we do this, the reference on 3.2.2 needs an edit.) --MF, 8/31/18On this page, you will use your ADTs with the map
block to display all the names in your contact list.
As you know, the keep
block allows you to check every item in a list using a predicate, and it reports only the items that make the predicate true. The block also lets you work across a whole list at once.
Map
allows you to perform the same function on every item of a list. Map
takes two inputs: a function (a reporter with a blank input slot) and a list, and it reports a new list. Every item in this new list is the result of calling the function with an item from the original list as input. For example:
You write the function that describes the change, and map
applies that function to each item in the input list and then reports the list of values reported by the function.
Notice that the function mapped over the list always has a blank input slot. With both map
and keep
that blank is required. This blank is where the list item goes each time the function is performed.
keep
block, map
isn't installed automatically. It has already been added to this project, but in other projects, you'll need to select "Import tools" from the File menu to access the map
block. map
. Discuss and then explain in writing what these expressions are doing.map
block together with your selectors to report a list of only the names of all contacts.Map
Block
This question refers to these two lists:
Which of these statements are true?
Choose all that apply.
map
puts a single item from words and numbers
into that slot.