Transforming Data10% of the exam

Core DataWeave collection functions

Predict what map, reduce, groupBy, pluck, mapObject, joinBy, flatten and distinctBy return, including the $, $$ and $$$ placeholders, reduce's default accumulator and the shape (array, object or string) each function produces.

Official exam objective
Predict the result of core DataWeave functions.

~7 min read · 7 practice questions ·

What the exam expects

  • Predict the output of map and pluck when the lambda uses the $, $$ and $$$ placeholders.
  • Trace reduce step by step with and without an initial accumulator value, including on an empty array.
  • Predict the shape groupBy returns (an object of arrays) and tell pluck (array) from mapObject (object).
  • Turn an array into a String with joinBy or reduce, and predict flatten and distinctBy on nested or duplicate data.
  • Key terms: lambda (anonymous function passed to a function such as (item, index) -> ...); placeholder ($, $$, $$$ used when the lambda's parameters are not named); accumulator (the running result reduce carries between iterations); criteria (the value a lambda returns that groupBy or distinctBy groups or de-duplicates on); dw::Core (the module of core functions every script imports automatically).

Key facts

Core module
Detail
dw::Core is imported automatically into every script
map placeholders
Detail
$ = item, $$ = zero-based index
pluck placeholders
Detail
$ = value, $$ = key, $$$ = index; returns an array
mapObject result
Detail
An object; the mapper returns an object
reduce placeholders
Detail
$ = item, $$ = accumulator
reduce default accumulator
Detail
First element; the lambda starts with the second
reduce on []
Detail
null with no initial value; the initial value otherwise
groupBy result
Detail
Object keyed by criteria values; each value an array of whole items
joinBy
Detail
Array to a single String with the separator between items
flatten depth
Detail
One level only; empty subarrays omitted
distinctBy
Detail
Lambda result is the uniqueness criteria; original items returned
Sources for this section (9)
  • What do the documented multiply examples return for [2,3,3] with no initial value and for [2,2,3] with acc = 3?
  • Why must a mapObject mapper return an object rather than a bare value?
  • When does reduce return null?
  • When should you choose pluck over mapObject?
  • When would a script need a second flatten?

The questions are free to read. Answers with their sources and self-grading are included with the pack.

Keep reading with the MuleSoft Developer pack

  • Core concepts
  • Exam traps
  • Worked scenario

The pack includes:

  • All 40 lessons of the MuleSoft Developer guide, with reading progress
  • Interactive decision walks and step-by-step sequence steppers
  • Practice exams purchase adds inline bank questions and topic practice (7 questions for this lesson)
  • An official source cited for every claim
  • An AI tutor that answers from the guide
  • Unlimited timed practice exams

Practice for the MuleSoft Developer exam