Combine

This page feels a little short, which is fine, but is there more to say here? --MF
    Even if there are two blanks in map, there's still only one input
  1. Try this experiment. Make map addition over (1,2,3,4) and combine with addition (1,2,3,4). Talk with Your Partner What is going into the blank addition spaces for map? What seems to be going in the blanks for combine with?
  2. Make a block max of () and () that returns the larger of two inputs.
  3. Make map max over list 1 4 9 5 and combine with max (1,4,9,5). Talk with Your Partner What is going into the blank spaces for max? What seems to be going in the blanks for combine with?

Ways to Think About It. When you see this:

The grey ring around the addition signals that you're going to apply the addition function to all of the elements of the list.
What's up with the semicolons in {1;2;3;4}? --MF
combine with addition (1,2,3,4)
think "I'm going to combine all the elements of {1;2;3;4} using addition."
In other words, "I'm going to add up all the elements of {1;2;3;4}"

Combine with is most useful with functions that take two inputs like:
sum block product block join block join words (2 blanks) and predicate block or predicate blockor the max function that you defined above.

These operations are associative, which means that the result is the same no matter how the items are grouped. For example, (3 + 4) + 5 = 3 + (4 + 5) and join words("the cat")("sat") = join words("the")("cat sat").

  1. Moral of the story: don't use subtraction or division in combine with because the grouping of the items matters in these cases. For example, (3 - 4) - 5 ≠ 3 - (4 - 5).
    Well, what happens if you drag non-associative blocks such as difference block or quotient block into combine with? Try it.
  2. Build a block sum that takes a list of numbeers and reports their sum.
  3. average
    = (sum of numbers) / (number of numbers)
    Click on the script to open a new project.
    list of 2-digit numbers
    Edit the block definition for average(grades) to report the average of a list of grades. Use your block to find the average of numbers.
  1. Talk with Your Partner You met the factorial function before (see this example). It takes a positive integer input n and reports the product of all the positive integers between 1 and n. Make a block factorial that models this using combine with.

    factorial of 5