SlideShare a Scribd company logo
1 of 32
July 21, 2023 12:30pm (EST)
Oklahoma City MuleSoft Meetup Group
The Secrets of Dataweave
2
● Introductions
● Our Sponsors
● The Secrets of Dataweave
● Trivia Game
● SPECIAL Dataweave Challenge!!!
● Exciting announcements
Welcome!
3
●Meet the Organizers:
○ Victor Felisbino
○ Ryan Hoegg
○ Diane Kesler
●Meet the Sponsors:
○ AVIO Consulting – Mike Slack
○ Hoegg Software - Ryan Hoegg
Introductions
Where are you joining this Meetup From?
The Secrets of Dataweave
Juan Cruz Basso
Senior Software Engineer at
Avio Consulting
• Software Engineer
• 13+ years in the world of integrations
• MuleSoft Certified Developer L1/L2
• MuleSoft Certified Integration Architect
• MuleSoft Certified Platform Architect
• MuleSoft Mentor
/jcbasso
Agenda
● Dataweave basic structure
● Functional programing principal concepts
● Functional concepts applied in Dataweave
● Modularization
● Demo
● Dataweave tips
● Q & A
Structure of a Dataweave Script
● It has a header and a body separated by (---)
○ Header: Contains language directives, such as input/output format, the version of DataWeave to
execute, properties of readers/writers, and definitions of variables or functions.
○ Body: Contains the DataWeave expression that generates the output of the script.
7
Functional programming concepts
● Pure functions
● First class functions
● High order functions
● Lamda functions
● Function composition
Pure Functions
%dw 2.0
output application/java
fun incOne(param,param2) = param + 1
—
incOne(payload,1)
9
Payload: 1
Payload: 2
incOne(1,1) Payload: 2
incOne(2,1) Payload: 3
%dw 2.0
output application/java
fun incOne(param,param2) = param + 1
—
payload incOne 1
Execution Nro 1
Execution Nro 2
Infix Notation Prefix Notation
First Class Functions
%dw 2.0
output application/java
fun incOne(param) = param + 1
fun processArray(array, func) = array map
func($)
—
processArray(payload,incOne)
10
%dw 2.0
output application/java
fun incOne(param) = param + 1
fun processArray(array, func) = array map
func($)
—
payload processArray incOne
%dw 2.0
output application/java
var incOne = (param) -> param
+ 1
—
incOne(payload)
%dw 2.0
output application/java
fun incOne(param) = param +
1
—
payload incOne
Declare a function as a variable
Infix Notation
Prefix Notation
High Order Functions
11
%dw 2.0
output application/java
var inputData = [1]
fun processArray(array, func) = array map func($)
fun incrementFunction(increment1) = (increment2) -> (increment1 + increment2)
fun incOne(param) = incrementFunction(1)(param)
fun incTwo(param) = incrementFunction(2)(param)
---
processArray(inputData,incOne) ++ processArray(inputData,incTwo) ++ processArray(inputData,incrementFunction(5))
Function Composition
12
%dw 2.0
output application/java
var arrayInput = ["string1", "string2", "1string3"]
---
((arrayInput filter ($ contains "1"))
map (item,index) -> upper(item) ++ index)
%dw 2.0
output application/java
var arrayInput = ["string1", "string2", "1string3"]
var filterItems = (item,index) -> item contains "1"
fun upperPlusIndex(item,index) = upper(item) ++ index
---
map( filter (arrayInput,filterItems) , upperPlusIndex)
Prefix Notation
Infix Notation
Core Functions
● They are functions created for data transformation, and it is not necessary to explicitly import them
in the scripts.
● Think of them as tools for solving different problems, there are more libraries around, but they
need to be explicitly imported.
● Some commonly used core functions are:
○ map
○ filter
○ reduce
○ isEmpty
○ flatten
○ flatMap
○ pluck
○ sizeOf
○ read
○ write
○ …
Modularization
● Promotes code reusability
● Inside of them we can define functions, variables, types, or Dataweave scripts.
● Functions are imported by using the module name followed by ::
○ We can import all the elements of the module using:
■ import * from modules::utilsModule
○ We can import specific elements of the module using:
■ import numberToSAP from modules::utilsModule
Modularization in a Mulesoft API
● Promotes code reusability within the implementation of a single MuleSoft API.
● They are located within the "resources" folder of the MuleSoft application.
15
Modularization as an Exchange Library
● Promotes code reusability within the implementation of multiple MuleSoft APIs.
● They are published on Exchange.
● They are included as Maven dependencies in the project's pom.xml file.
● MuleSoft Runtime
● CLI scripts
● Playground
● VS Code
● Dataweave in Apex (Beta)
Execution contexts
17
Demo
Tips when developing with Dataweave
● Use do to create partial context of execution to define “local” variables
● Use log() to trace intermediate results of the transformations for troubleshooting
● The object destructor is a powerful tool to concatenate objects, or transform them into
key/value pairs. (aka surround with () and then with {} )
● Be aware of the in the usage of () in the correct way, the parenthesis defines the scope of the
results and how the operations like ! or functions will impact.
Links
● https://dataweave.mulesoft.com
● https://docs.mulesoft.com/dataweave/2.4/dataweave-language-guide
● Core functions doc: https://docs.mulesoft.com/dataweave/2.4/dw-core
● Cheat Sheet : https://www.prostdev.com/post/dataweave-2-0-core-functions-cheatsheet
● Memory management : https://docs.mulesoft.com/dataweave/2.4/dataweave-memory-
management#buffersize
● Dataweave in Apex (Beta): https://developer.salesforce.com/docs/atlas.en-
us.apexcode.meta/apexcode/DataWeaveInApex.htm
Trivia Game!
22
Trivia Game
Three winners of today’s trivia
receives:
A $30 Gift Card!
● Remember:
○ The first correct answer wins!
○ You can only receive 1 Gift Card
● Gift Cards are sponsored by
23
1. How many parameters should have a function to be used with an
infix notation?
A. 1
B. 3
C. 2
D. any
Trivia Question 1
24
2. How many functions can I pass as parameters in a function in
Datawave?
A. 1
B. any
C. 2
D. 0
Trivia Question 2
25
3. When a function is a first-class function in a programming
language?
A. when it flights only in first class
B. when it's the first function written in the code
C. when it can be treated as an object ( having the same
"privileges" )
D. when it's the first function called of a program
Trivia Question 3
DATA WEAVE CHALLENGE!
27
Dataweave Challenge!
input : [{
"message": "Hello world 1!",
"weight": 1,
"color": "red"
}
,
{
"message": "Hello world 2!",
"weight": 2,
"color": "blue"
}
,
{
"message": "Hello world 3!",
"weight": 3,
"color": "green"
}
]
output: {
"byWeight": [
{
"message": "Hello world 3!",
"weight": 3,
"color": "green"
}
],
"byColor": [
{
"message": "Hello world 2!",
"weight": 2,
"color": "blue"
}
]
}
Here is your Input Desired Output
script: %dw 2.0
output application/json
---
{
byWeight: payload filterByWeight 3,
byColor: payload filterByColor 'blue'
}
?
Send us your
Functions!
What’s Next?
● Share:
○ Tweet using the hashtag #MuleSoftMeetups
○ Invite your network to join: https://meetups.mulesoft.com/oklahoma-city/
○ Want to be a Speaker? Let us know at:
● Feedback:
○ Fill out the survey feedback – Win MuleSoft Swag! Drawing from completed surveys
○ Suggest topics for upcoming events: What are YOUR requests?
○ Contact MuleSoft at meetups@mulesoft.com for ways to improve the program
29
What’s next?
30
We are here
to help YOU!
Thank you & See you next time!

More Related Content

Similar to 20230721_OKC_Meetup_MuleSoft.pptx

Writing DSL with Applicative Functors
Writing DSL with Applicative FunctorsWriting DSL with Applicative Functors
Writing DSL with Applicative FunctorsDavid Galichet
 
An Overview Of Python With Functional Programming
An Overview Of Python With Functional ProgrammingAn Overview Of Python With Functional Programming
An Overview Of Python With Functional ProgrammingAdam Getchell
 
PyData NYC 2019
PyData NYC 2019PyData NYC 2019
PyData NYC 2019Li Jin
 
Hack Like It's 2013 (The Workshop)
Hack Like It's 2013 (The Workshop)Hack Like It's 2013 (The Workshop)
Hack Like It's 2013 (The Workshop)Itzik Kotler
 
IIM.Com-FIT-Unit2(14.9.2021 TO 30.9.2021).pptx
IIM.Com-FIT-Unit2(14.9.2021 TO 30.9.2021).pptxIIM.Com-FIT-Unit2(14.9.2021 TO 30.9.2021).pptx
IIM.Com-FIT-Unit2(14.9.2021 TO 30.9.2021).pptxrajkumar490591
 
Computer Project For Class XII Topic - The Snake Game
Computer Project For Class XII Topic - The Snake Game Computer Project For Class XII Topic - The Snake Game
Computer Project For Class XII Topic - The Snake Game Pritam Samanta
 
Exploring Clojurescript
Exploring ClojurescriptExploring Clojurescript
Exploring ClojurescriptLuke Donnet
 
Things about Functional JavaScript
Things about Functional JavaScriptThings about Functional JavaScript
Things about Functional JavaScriptChengHui Weng
 
No Coding Necessary: Building User Macros and Dynamic Reports Inside Confluen...
No Coding Necessary: Building User Macros and Dynamic Reports Inside Confluen...No Coding Necessary: Building User Macros and Dynamic Reports Inside Confluen...
No Coding Necessary: Building User Macros and Dynamic Reports Inside Confluen...Atlassian
 
Introduction to D programming language at Weka.IO
Introduction to D programming language at Weka.IOIntroduction to D programming language at Weka.IO
Introduction to D programming language at Weka.IOLiran Zvibel
 

Similar to 20230721_OKC_Meetup_MuleSoft.pptx (20)

Writing DSL with Applicative Functors
Writing DSL with Applicative FunctorsWriting DSL with Applicative Functors
Writing DSL with Applicative Functors
 
An Overview Of Python With Functional Programming
An Overview Of Python With Functional ProgrammingAn Overview Of Python With Functional Programming
An Overview Of Python With Functional Programming
 
PyData NYC 2019
PyData NYC 2019PyData NYC 2019
PyData NYC 2019
 
Hack Like It's 2013 (The Workshop)
Hack Like It's 2013 (The Workshop)Hack Like It's 2013 (The Workshop)
Hack Like It's 2013 (The Workshop)
 
IIM.Com-FIT-Unit2(14.9.2021 TO 30.9.2021).pptx
IIM.Com-FIT-Unit2(14.9.2021 TO 30.9.2021).pptxIIM.Com-FIT-Unit2(14.9.2021 TO 30.9.2021).pptx
IIM.Com-FIT-Unit2(14.9.2021 TO 30.9.2021).pptx
 
C++ Programming
C++ ProgrammingC++ Programming
C++ Programming
 
Oops lecture 1
Oops lecture 1Oops lecture 1
Oops lecture 1
 
C++ Overview PPT
C++ Overview PPTC++ Overview PPT
C++ Overview PPT
 
C++
C++C++
C++
 
Computer Project For Class XII Topic - The Snake Game
Computer Project For Class XII Topic - The Snake Game Computer Project For Class XII Topic - The Snake Game
Computer Project For Class XII Topic - The Snake Game
 
Novidades do c# 7 e 8
Novidades do c# 7 e 8Novidades do c# 7 e 8
Novidades do c# 7 e 8
 
Introduction to F#
Introduction to F#Introduction to F#
Introduction to F#
 
C++ Programming
C++ ProgrammingC++ Programming
C++ Programming
 
Exploring Clojurescript
Exploring ClojurescriptExploring Clojurescript
Exploring Clojurescript
 
Dartprogramming
DartprogrammingDartprogramming
Dartprogramming
 
Gui
GuiGui
Gui
 
Things about Functional JavaScript
Things about Functional JavaScriptThings about Functional JavaScript
Things about Functional JavaScript
 
mobl
moblmobl
mobl
 
No Coding Necessary: Building User Macros and Dynamic Reports Inside Confluen...
No Coding Necessary: Building User Macros and Dynamic Reports Inside Confluen...No Coding Necessary: Building User Macros and Dynamic Reports Inside Confluen...
No Coding Necessary: Building User Macros and Dynamic Reports Inside Confluen...
 
Introduction to D programming language at Weka.IO
Introduction to D programming language at Weka.IOIntroduction to D programming language at Weka.IO
Introduction to D programming language at Weka.IO
 

Recently uploaded

Science&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdfScience&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdfjimielynbastida
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDGMarianaLemus7
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Neo4j
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 

Recently uploaded (20)

Science&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdfScience&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdf
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDG
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort ServiceHot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 

20230721_OKC_Meetup_MuleSoft.pptx

  • 1. July 21, 2023 12:30pm (EST) Oklahoma City MuleSoft Meetup Group The Secrets of Dataweave
  • 2. 2 ● Introductions ● Our Sponsors ● The Secrets of Dataweave ● Trivia Game ● SPECIAL Dataweave Challenge!!! ● Exciting announcements Welcome!
  • 3. 3 ●Meet the Organizers: ○ Victor Felisbino ○ Ryan Hoegg ○ Diane Kesler ●Meet the Sponsors: ○ AVIO Consulting – Mike Slack ○ Hoegg Software - Ryan Hoegg Introductions Where are you joining this Meetup From?
  • 4. The Secrets of Dataweave
  • 5. Juan Cruz Basso Senior Software Engineer at Avio Consulting • Software Engineer • 13+ years in the world of integrations • MuleSoft Certified Developer L1/L2 • MuleSoft Certified Integration Architect • MuleSoft Certified Platform Architect • MuleSoft Mentor /jcbasso
  • 6. Agenda ● Dataweave basic structure ● Functional programing principal concepts ● Functional concepts applied in Dataweave ● Modularization ● Demo ● Dataweave tips ● Q & A
  • 7. Structure of a Dataweave Script ● It has a header and a body separated by (---) ○ Header: Contains language directives, such as input/output format, the version of DataWeave to execute, properties of readers/writers, and definitions of variables or functions. ○ Body: Contains the DataWeave expression that generates the output of the script. 7
  • 8. Functional programming concepts ● Pure functions ● First class functions ● High order functions ● Lamda functions ● Function composition
  • 9. Pure Functions %dw 2.0 output application/java fun incOne(param,param2) = param + 1 — incOne(payload,1) 9 Payload: 1 Payload: 2 incOne(1,1) Payload: 2 incOne(2,1) Payload: 3 %dw 2.0 output application/java fun incOne(param,param2) = param + 1 — payload incOne 1 Execution Nro 1 Execution Nro 2 Infix Notation Prefix Notation
  • 10. First Class Functions %dw 2.0 output application/java fun incOne(param) = param + 1 fun processArray(array, func) = array map func($) — processArray(payload,incOne) 10 %dw 2.0 output application/java fun incOne(param) = param + 1 fun processArray(array, func) = array map func($) — payload processArray incOne %dw 2.0 output application/java var incOne = (param) -> param + 1 — incOne(payload) %dw 2.0 output application/java fun incOne(param) = param + 1 — payload incOne Declare a function as a variable Infix Notation Prefix Notation
  • 11. High Order Functions 11 %dw 2.0 output application/java var inputData = [1] fun processArray(array, func) = array map func($) fun incrementFunction(increment1) = (increment2) -> (increment1 + increment2) fun incOne(param) = incrementFunction(1)(param) fun incTwo(param) = incrementFunction(2)(param) --- processArray(inputData,incOne) ++ processArray(inputData,incTwo) ++ processArray(inputData,incrementFunction(5))
  • 12. Function Composition 12 %dw 2.0 output application/java var arrayInput = ["string1", "string2", "1string3"] --- ((arrayInput filter ($ contains "1")) map (item,index) -> upper(item) ++ index) %dw 2.0 output application/java var arrayInput = ["string1", "string2", "1string3"] var filterItems = (item,index) -> item contains "1" fun upperPlusIndex(item,index) = upper(item) ++ index --- map( filter (arrayInput,filterItems) , upperPlusIndex) Prefix Notation Infix Notation
  • 13. Core Functions ● They are functions created for data transformation, and it is not necessary to explicitly import them in the scripts. ● Think of them as tools for solving different problems, there are more libraries around, but they need to be explicitly imported. ● Some commonly used core functions are: ○ map ○ filter ○ reduce ○ isEmpty ○ flatten ○ flatMap ○ pluck ○ sizeOf ○ read ○ write ○ …
  • 14. Modularization ● Promotes code reusability ● Inside of them we can define functions, variables, types, or Dataweave scripts. ● Functions are imported by using the module name followed by :: ○ We can import all the elements of the module using: ■ import * from modules::utilsModule ○ We can import specific elements of the module using: ■ import numberToSAP from modules::utilsModule
  • 15. Modularization in a Mulesoft API ● Promotes code reusability within the implementation of a single MuleSoft API. ● They are located within the "resources" folder of the MuleSoft application. 15
  • 16. Modularization as an Exchange Library ● Promotes code reusability within the implementation of multiple MuleSoft APIs. ● They are published on Exchange. ● They are included as Maven dependencies in the project's pom.xml file.
  • 17. ● MuleSoft Runtime ● CLI scripts ● Playground ● VS Code ● Dataweave in Apex (Beta) Execution contexts 17
  • 18. Demo
  • 19. Tips when developing with Dataweave ● Use do to create partial context of execution to define “local” variables ● Use log() to trace intermediate results of the transformations for troubleshooting ● The object destructor is a powerful tool to concatenate objects, or transform them into key/value pairs. (aka surround with () and then with {} ) ● Be aware of the in the usage of () in the correct way, the parenthesis defines the scope of the results and how the operations like ! or functions will impact.
  • 20. Links ● https://dataweave.mulesoft.com ● https://docs.mulesoft.com/dataweave/2.4/dataweave-language-guide ● Core functions doc: https://docs.mulesoft.com/dataweave/2.4/dw-core ● Cheat Sheet : https://www.prostdev.com/post/dataweave-2-0-core-functions-cheatsheet ● Memory management : https://docs.mulesoft.com/dataweave/2.4/dataweave-memory- management#buffersize ● Dataweave in Apex (Beta): https://developer.salesforce.com/docs/atlas.en- us.apexcode.meta/apexcode/DataWeaveInApex.htm
  • 22. 22 Trivia Game Three winners of today’s trivia receives: A $30 Gift Card! ● Remember: ○ The first correct answer wins! ○ You can only receive 1 Gift Card ● Gift Cards are sponsored by
  • 23. 23 1. How many parameters should have a function to be used with an infix notation? A. 1 B. 3 C. 2 D. any Trivia Question 1
  • 24. 24 2. How many functions can I pass as parameters in a function in Datawave? A. 1 B. any C. 2 D. 0 Trivia Question 2
  • 25. 25 3. When a function is a first-class function in a programming language? A. when it flights only in first class B. when it's the first function written in the code C. when it can be treated as an object ( having the same "privileges" ) D. when it's the first function called of a program Trivia Question 3
  • 27. 27 Dataweave Challenge! input : [{ "message": "Hello world 1!", "weight": 1, "color": "red" } , { "message": "Hello world 2!", "weight": 2, "color": "blue" } , { "message": "Hello world 3!", "weight": 3, "color": "green" } ] output: { "byWeight": [ { "message": "Hello world 3!", "weight": 3, "color": "green" } ], "byColor": [ { "message": "Hello world 2!", "weight": 2, "color": "blue" } ] } Here is your Input Desired Output script: %dw 2.0 output application/json --- { byWeight: payload filterByWeight 3, byColor: payload filterByColor 'blue' } ? Send us your Functions!
  • 29. ● Share: ○ Tweet using the hashtag #MuleSoftMeetups ○ Invite your network to join: https://meetups.mulesoft.com/oklahoma-city/ ○ Want to be a Speaker? Let us know at: ● Feedback: ○ Fill out the survey feedback – Win MuleSoft Swag! Drawing from completed surveys ○ Suggest topics for upcoming events: What are YOUR requests? ○ Contact MuleSoft at meetups@mulesoft.com for ways to improve the program 29 What’s next?
  • 30. 30 We are here to help YOU!
  • 31.
  • 32. Thank you & See you next time!