Sort the collection operator
Select the right collection operator by recognizing the intended shape change.
Match each collection task to the operator that best communicates its shape change. map filter reduce flatMap Turn each order into one invoice row One input order becomes one output row, so map states the one-to-one transformation. Keep only accounts with active subscriptions The item shape stays the same while the collection shrinks to matching accounts. Sum all invoice line amounts into one total Many line values collapse into one accumulated total, which is reduce's contract. Turn each customer into zero, one, or many notification messages Each customer may expand to multiple messages, and flatMap removes the nested lists. Convert…
Sign up free — one personalized lesson every day, matched to your role and goals.
Already have an account? Sign in