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.
Predict the result of core DataWeave functions.
~7 min read · 7 practice questions ·
What the exam expects
- Predict the output of
mapandpluckwhen the lambda uses the$,$$and$$$placeholders. - Trace
reducestep by step with and without an initial accumulator value, including on an empty array. - Predict the shape
groupByreturns (an object of arrays) and tellpluck(array) frommapObject(object). - Turn an array into a String with
joinByorreduce, and predictflattenanddistinctByon 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 resultreducecarries between iterations); criteria (the value a lambda returns thatgroupByordistinctBygroups or de-duplicates on); dw::Core (the module of core functions every script imports automatically).
Key facts
Core module
- Detail
dw::Coreis imported automatically into every script
map placeholders- Detail
$= item,$$= zero-based index- Source
- map (opens in a new tab)
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
nullwith 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)
- Core (dw::Core)docs.mulesoft.com (opens in a new tab)
- mapdocs.mulesoft.com (opens in a new tab)
- pluckdocs.mulesoft.com (opens in a new tab)
- mapObjectdocs.mulesoft.com (opens in a new tab)
- reducedocs.mulesoft.com (opens in a new tab)
- groupBydocs.mulesoft.com (opens in a new tab)
- joinBydocs.mulesoft.com (opens in a new tab)
- flattendocs.mulesoft.com (opens in a new tab)
- distinctBydocs.mulesoft.com (opens in a new tab)
- What do the documented multiply examples return for
[2,3,3]with no initial value and for[2,2,3]withacc = 3? - Why must a
mapObjectmapper return an object rather than a bare value? - When does
reducereturn null? - When should you choose
pluckovermapObject? - 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