SlideShare a Scribd company logo
1 of 19
Download to read offline
Functional
Domain
ModelingBy /MichalBigos @teliatko
Agenda
1. FunctionalProgrammingGems
2. Example
3. Perception of State
4. What's Next...
Functional Programming Gems
Pure Functions
Functions w/o side-effects
Theyare referentialytransparent
//Definitionoffunction
defsomeComputation(value:Long):Long=value+3
//Definitionasfunctionliteral
valanotherComputation:(Long)=>Long=(value:Long)=>value+3
Functional Programming Gems
Immutable Data
Dataw/o shared mutable state
Theycan be shared freely... no locks, no semafores etc.
//Definitionofcaseobjects
sealedtraitProgrammingLanguageKind
caseobjectStaticextendsProgrammingLanguageKind
caseobjectDynamicextendsProgrammingLanguageKind
//Definitionofcaseclass
caseclassProgrammingLanguage(
name:String,
kind:ProgrammingLanguageKind
)
Functional Programming Gems
Persistent Data Structures
Always preserves the previous version of itself when itis
modified
Effectivelyimmutable with no in-place mutation
//Supposewehavealist...
vall1=List(1,2,3)
//Thenweaddaitemtoit
vall2=4::l
assert(l1!=l2)//yieldstrue
Functional Programming Gems
Algebraic Data Types, take one
An algebraic datatype is akind of composite type, i.e. atype
formed bycombiningother types
Datatypes with some algebra, i.e. structure and operations
Unit type, Sumtypeand Product type
e.g. Lists can byformalydescribed as L = I + X * L
valemptyList=List()//Unittype
valsimpleList=1::emptyList//Sumtype
valproductList=2::emptyList//Producttype
Functional Programming Gems
Algebraic Data Types, take two
Domain entities are represented usingproduct types
caseclasses are bestfitin Scala
//Tupleissimplestproducttype
valprogrammingLanguage=(name,kind)
//Producttypeviacaseclass
caseclassProgrammingLanguage(
name:String,
kind:ProgrammingLanguageKind
)
Functional Programming Gems
Algebraic Data Types, take three
Domain values and enums are represented usingsumtypes
Inheritance and sealed traits/classes are bestfitin Scala
//Exampleofsum-type,OptionfromScalalibrary(codesimplified)
sealedabstractclassOption[+A]
finalcaseclassSome[+A](x:A)extendsOption[A]
caseobjectNoneextendsOption[Nothing]
//Sumtypeviacaseobjects
sealedtraitProgrammingLanguageKind
caseobjectStaticextendsProgrammingLanguageKind
caseobjectDynamicextendsProgrammingLanguageKind
Functional Programming Gems
Function Composition
Functions compose when theycause no side-effects
Side-effects do notcompose
scala>deffoo(something:String):String=s"foo($something)"
scala>defbar(something:String):String=s"bar($something)"
valcomposit=foo_composebar_
valreverseComposit=foo_andThenbar_
composit("anything")
>foo(bar(anything))
reverseComposit("anything")
>bar(foo(anything))
Functional Programming Gems
Combinators
Applyhigh-order functions
Glue for chainingfunctions
Pure functions as domain invariants and behavior
foundmap{foundLine=>partitions.success}
| |
Combinator High-orderfn
Monadicchaining,viafor-comprehensions
for{ |
_<-quantityInvariant(quantity)
_<-priceInvariant(price)
(found,rest)<-productAlreadyExists(productId)
}yield{/*dosomething*/}
Functional Programming Gems
Side Effects
FP languages encourage isolatingside-effects from pure
domain logic
Known side-effects (notinsignigicant)
1. DBaccess
2. Logging
3. IO operations
Example
result.foreach{case(order,event)=>
orderRepository.saveOrUpdate(order)
}
Functional Programming Gems
More to cover
Ad-hoc polymorphism viaTypeClasses
Type-Lenses functionalupdates in your domain model
Example
Perception of State
Domain state is effecivelymutable
Can retain previous states
Historyof whathappened
In-place mutation are wrongfor domain model
Theycombine state with time
What's next
Event Sourcing
Everystate-modification on domain yields event
Domain change is achieved byapplyingthe eventto the
aggregate
Eventstream, allthe events applied on domain
What's next
CQRS
Commands execute operations on domain model
Queries arbitraryviews of data
Independentscalability
What's next
Memory Image and STM
Application state in memory
Application of events to currentstate on domain
Enables transactions on memory
Interesting Links
1.
2.
3.
4.
5.
6.
7.
8.
PureFunction(Wikipedia)
Referenctial Transparency(Wikipedia)
Persistent Data Structure(Wikipedia)
Presistend Data Structures and Managed References
ADT, Product and SumTypes (Bob Harper, PFPL)
SimpleMadeEasy(RichHickey)
FunctionComposition(Wikipedia)
Building Apps w/ Functional DomainModels (Debasish
Ghosh)
Thanks for your attention

More Related Content

What's hot

Basic concept of oops
Basic concept of oopsBasic concept of oops
Basic concept of oopsPadma Kannan
 
Structures in c language
Structures in c languageStructures in c language
Structures in c languagetanmaymodi4
 
Type casting in java
Type casting in javaType casting in java
Type casting in javaFarooq Baloch
 
Search for a substring of characters using the theory of non-deterministic fi...
Search for a substring of characters using the theory of non-deterministic fi...Search for a substring of characters using the theory of non-deterministic fi...
Search for a substring of characters using the theory of non-deterministic fi...journalBEEI
 
Exploring Strategies for Training Deep Neural Networks paper review
Exploring Strategies for Training Deep Neural Networks paper reviewExploring Strategies for Training Deep Neural Networks paper review
Exploring Strategies for Training Deep Neural Networks paper reviewVimukthi Wickramasinghe
 
Object oriented programming C++
Object oriented programming C++Object oriented programming C++
Object oriented programming C++AkshtaSuryawanshi
 
CPU : Structures And Unions
CPU : Structures And UnionsCPU : Structures And Unions
CPU : Structures And UnionsDhrumil Patel
 
Presentation on c programing satcture
Presentation on c programing satcture Presentation on c programing satcture
Presentation on c programing satcture topu93
 
Presentation on c structures
Presentation on c   structures Presentation on c   structures
Presentation on c structures topu93
 
Lecture 12
Lecture 12Lecture 12
Lecture 12Rana Ali
 
Neural Nets Deconstructed
Neural Nets DeconstructedNeural Nets Deconstructed
Neural Nets DeconstructedPaul Sterk
 
Java8 and Functional Programming
Java8 and Functional ProgrammingJava8 and Functional Programming
Java8 and Functional ProgrammingYiguang Hu
 
Data Structure Interview Questions & Answers
Data Structure Interview Questions & AnswersData Structure Interview Questions & Answers
Data Structure Interview Questions & AnswersSatyam Jaiswal
 

What's hot (20)

Structures in c++
Structures in c++Structures in c++
Structures in c++
 
Structure in c
Structure in cStructure in c
Structure in c
 
Structure in c
Structure in cStructure in c
Structure in c
 
Basic concept of oops
Basic concept of oopsBasic concept of oops
Basic concept of oops
 
Structures in c language
Structures in c languageStructures in c language
Structures in c language
 
Type casting in java
Type casting in javaType casting in java
Type casting in java
 
Structure in C
Structure in CStructure in C
Structure in C
 
Search for a substring of characters using the theory of non-deterministic fi...
Search for a substring of characters using the theory of non-deterministic fi...Search for a substring of characters using the theory of non-deterministic fi...
Search for a substring of characters using the theory of non-deterministic fi...
 
SEMINAR
SEMINARSEMINAR
SEMINAR
 
Exploring Strategies for Training Deep Neural Networks paper review
Exploring Strategies for Training Deep Neural Networks paper reviewExploring Strategies for Training Deep Neural Networks paper review
Exploring Strategies for Training Deep Neural Networks paper review
 
Structure in c sharp
Structure in c sharpStructure in c sharp
Structure in c sharp
 
Object oriented programming C++
Object oriented programming C++Object oriented programming C++
Object oriented programming C++
 
CPU : Structures And Unions
CPU : Structures And UnionsCPU : Structures And Unions
CPU : Structures And Unions
 
Presentation on c programing satcture
Presentation on c programing satcture Presentation on c programing satcture
Presentation on c programing satcture
 
Presentation on c structures
Presentation on c   structures Presentation on c   structures
Presentation on c structures
 
Lecture 12
Lecture 12Lecture 12
Lecture 12
 
Neural Nets Deconstructed
Neural Nets DeconstructedNeural Nets Deconstructed
Neural Nets Deconstructed
 
Java8 and Functional Programming
Java8 and Functional ProgrammingJava8 and Functional Programming
Java8 and Functional Programming
 
Type casting
Type castingType casting
Type casting
 
Data Structure Interview Questions & Answers
Data Structure Interview Questions & AnswersData Structure Interview Questions & Answers
Data Structure Interview Questions & Answers
 

Similar to Functional Domain Modeling

Interview preparation for programming.pptx
Interview preparation for programming.pptxInterview preparation for programming.pptx
Interview preparation for programming.pptxBilalHussainShah5
 
Fun with Functional Programming in Clojure
Fun with Functional Programming in ClojureFun with Functional Programming in Clojure
Fun with Functional Programming in ClojureCodemotion
 
These questions will be a bit advanced level 2
These questions will be a bit advanced level 2These questions will be a bit advanced level 2
These questions will be a bit advanced level 2sadhana312471
 
Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009Martin Odersky
 
Thinking Functionally - John Stevenson - Codemotion Rome 2017
Thinking Functionally - John Stevenson - Codemotion Rome 2017Thinking Functionally - John Stevenson - Codemotion Rome 2017
Thinking Functionally - John Stevenson - Codemotion Rome 2017Codemotion
 
Thinking Functionally with Clojure
Thinking Functionally with ClojureThinking Functionally with Clojure
Thinking Functionally with ClojureJohn Stevenson
 
Xml processing-by-asfak
Xml processing-by-asfakXml processing-by-asfak
Xml processing-by-asfakAsfak Mahamud
 
A Survey of Concurrency Constructs
A Survey of Concurrency ConstructsA Survey of Concurrency Constructs
A Survey of Concurrency ConstructsTed Leung
 
Functional web with clojure
Functional web with clojureFunctional web with clojure
Functional web with clojureJohn Stevenson
 
Get into Functional Programming with Clojure
Get into Functional Programming with ClojureGet into Functional Programming with Clojure
Get into Functional Programming with ClojureJohn Stevenson
 
Fun with Functional Programming in Clojure - John Stevenson - Codemotion Amst...
Fun with Functional Programming in Clojure - John Stevenson - Codemotion Amst...Fun with Functional Programming in Clojure - John Stevenson - Codemotion Amst...
Fun with Functional Programming in Clojure - John Stevenson - Codemotion Amst...Codemotion
 
Functional Patterns for C++ Multithreading (C++ Dev Meetup Iasi)
Functional Patterns for C++ Multithreading (C++ Dev Meetup Iasi)Functional Patterns for C++ Multithreading (C++ Dev Meetup Iasi)
Functional Patterns for C++ Multithreading (C++ Dev Meetup Iasi)Ovidiu Farauanu
 
02 sm3 xml_xp_03
02 sm3 xml_xp_0302 sm3 xml_xp_03
02 sm3 xml_xp_03Niit Care
 
About Functional Programming
About Functional ProgrammingAbout Functional Programming
About Functional ProgrammingAapo Kyrölä
 
Master in javascript
Master in javascriptMaster in javascript
Master in javascriptRobbin Zhao
 
Tour de Jackson: Forgotten Features of Jackson JSON processor
Tour de Jackson: Forgotten Features of Jackson JSON processorTour de Jackson: Forgotten Features of Jackson JSON processor
Tour de Jackson: Forgotten Features of Jackson JSON processorTatu Saloranta
 
Questions On The Code And Core Module
Questions On The Code And Core ModuleQuestions On The Code And Core Module
Questions On The Code And Core ModuleKatie Gulley
 
AJS UNIT-1 2021-converted.pdf
AJS UNIT-1 2021-converted.pdfAJS UNIT-1 2021-converted.pdf
AJS UNIT-1 2021-converted.pdfSreeVani74
 

Similar to Functional Domain Modeling (20)

Interview preparation for programming.pptx
Interview preparation for programming.pptxInterview preparation for programming.pptx
Interview preparation for programming.pptx
 
Fun with Functional Programming in Clojure
Fun with Functional Programming in ClojureFun with Functional Programming in Clojure
Fun with Functional Programming in Clojure
 
These questions will be a bit advanced level 2
These questions will be a bit advanced level 2These questions will be a bit advanced level 2
These questions will be a bit advanced level 2
 
Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009
 
Thinking Functionally - John Stevenson - Codemotion Rome 2017
Thinking Functionally - John Stevenson - Codemotion Rome 2017Thinking Functionally - John Stevenson - Codemotion Rome 2017
Thinking Functionally - John Stevenson - Codemotion Rome 2017
 
Thinking Functionally with Clojure
Thinking Functionally with ClojureThinking Functionally with Clojure
Thinking Functionally with Clojure
 
Xml processing-by-asfak
Xml processing-by-asfakXml processing-by-asfak
Xml processing-by-asfak
 
A Survey of Concurrency Constructs
A Survey of Concurrency ConstructsA Survey of Concurrency Constructs
A Survey of Concurrency Constructs
 
Functional web with clojure
Functional web with clojureFunctional web with clojure
Functional web with clojure
 
Get into Functional Programming with Clojure
Get into Functional Programming with ClojureGet into Functional Programming with Clojure
Get into Functional Programming with Clojure
 
Fun with Functional Programming in Clojure - John Stevenson - Codemotion Amst...
Fun with Functional Programming in Clojure - John Stevenson - Codemotion Amst...Fun with Functional Programming in Clojure - John Stevenson - Codemotion Amst...
Fun with Functional Programming in Clojure - John Stevenson - Codemotion Amst...
 
Functional Patterns for C++ Multithreading (C++ Dev Meetup Iasi)
Functional Patterns for C++ Multithreading (C++ Dev Meetup Iasi)Functional Patterns for C++ Multithreading (C++ Dev Meetup Iasi)
Functional Patterns for C++ Multithreading (C++ Dev Meetup Iasi)
 
Java chapter 3
Java   chapter 3Java   chapter 3
Java chapter 3
 
02 sm3 xml_xp_03
02 sm3 xml_xp_0302 sm3 xml_xp_03
02 sm3 xml_xp_03
 
About Functional Programming
About Functional ProgrammingAbout Functional Programming
About Functional Programming
 
Master in javascript
Master in javascriptMaster in javascript
Master in javascript
 
Tour de Jackson: Forgotten Features of Jackson JSON processor
Tour de Jackson: Forgotten Features of Jackson JSON processorTour de Jackson: Forgotten Features of Jackson JSON processor
Tour de Jackson: Forgotten Features of Jackson JSON processor
 
Modern C++
Modern C++Modern C++
Modern C++
 
Questions On The Code And Core Module
Questions On The Code And Core ModuleQuestions On The Code And Core Module
Questions On The Code And Core Module
 
AJS UNIT-1 2021-converted.pdf
AJS UNIT-1 2021-converted.pdfAJS UNIT-1 2021-converted.pdf
AJS UNIT-1 2021-converted.pdf
 

More from Michal Bigos

All About ... Functions
All About ... FunctionsAll About ... Functions
All About ... FunctionsMichal Bigos
 
Scala eXchange 2013 Report
Scala eXchange 2013 ReportScala eXchange 2013 Report
Scala eXchange 2013 ReportMichal Bigos
 
Dependency injection in scala
Dependency injection in scalaDependency injection in scala
Dependency injection in scalaMichal Bigos
 
Option, Either, Try and what to do with corner cases when they arise
Option, Either, Try and what to do with corner cases when they ariseOption, Either, Try and what to do with corner cases when they arise
Option, Either, Try and what to do with corner cases when they ariseMichal Bigos
 
Integration Testing With ScalaTest and MongoDB
Integration Testing With ScalaTest and MongoDBIntegration Testing With ScalaTest and MongoDB
Integration Testing With ScalaTest and MongoDBMichal Bigos
 

More from Michal Bigos (6)

All About ... Functions
All About ... FunctionsAll About ... Functions
All About ... Functions
 
Scala eXchange 2013 Report
Scala eXchange 2013 ReportScala eXchange 2013 Report
Scala eXchange 2013 Report
 
SBT Crash Course
SBT Crash CourseSBT Crash Course
SBT Crash Course
 
Dependency injection in scala
Dependency injection in scalaDependency injection in scala
Dependency injection in scala
 
Option, Either, Try and what to do with corner cases when they arise
Option, Either, Try and what to do with corner cases when they ariseOption, Either, Try and what to do with corner cases when they arise
Option, Either, Try and what to do with corner cases when they arise
 
Integration Testing With ScalaTest and MongoDB
Integration Testing With ScalaTest and MongoDBIntegration Testing With ScalaTest and MongoDB
Integration Testing With ScalaTest and MongoDB
 

Recently uploaded

#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
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
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGSujit Pal
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 

Recently uploaded (20)

#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
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
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAG
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 

Functional Domain Modeling

  • 2. Agenda 1. FunctionalProgrammingGems 2. Example 3. Perception of State 4. What's Next...
  • 3. Functional Programming Gems Pure Functions Functions w/o side-effects Theyare referentialytransparent //Definitionoffunction defsomeComputation(value:Long):Long=value+3 //Definitionasfunctionliteral valanotherComputation:(Long)=>Long=(value:Long)=>value+3
  • 4. Functional Programming Gems Immutable Data Dataw/o shared mutable state Theycan be shared freely... no locks, no semafores etc. //Definitionofcaseobjects sealedtraitProgrammingLanguageKind caseobjectStaticextendsProgrammingLanguageKind caseobjectDynamicextendsProgrammingLanguageKind //Definitionofcaseclass caseclassProgrammingLanguage( name:String, kind:ProgrammingLanguageKind )
  • 5. Functional Programming Gems Persistent Data Structures Always preserves the previous version of itself when itis modified Effectivelyimmutable with no in-place mutation //Supposewehavealist... vall1=List(1,2,3) //Thenweaddaitemtoit vall2=4::l assert(l1!=l2)//yieldstrue
  • 6. Functional Programming Gems Algebraic Data Types, take one An algebraic datatype is akind of composite type, i.e. atype formed bycombiningother types Datatypes with some algebra, i.e. structure and operations Unit type, Sumtypeand Product type e.g. Lists can byformalydescribed as L = I + X * L valemptyList=List()//Unittype valsimpleList=1::emptyList//Sumtype valproductList=2::emptyList//Producttype
  • 7. Functional Programming Gems Algebraic Data Types, take two Domain entities are represented usingproduct types caseclasses are bestfitin Scala //Tupleissimplestproducttype valprogrammingLanguage=(name,kind) //Producttypeviacaseclass caseclassProgrammingLanguage( name:String, kind:ProgrammingLanguageKind )
  • 8. Functional Programming Gems Algebraic Data Types, take three Domain values and enums are represented usingsumtypes Inheritance and sealed traits/classes are bestfitin Scala //Exampleofsum-type,OptionfromScalalibrary(codesimplified) sealedabstractclassOption[+A] finalcaseclassSome[+A](x:A)extendsOption[A] caseobjectNoneextendsOption[Nothing] //Sumtypeviacaseobjects sealedtraitProgrammingLanguageKind caseobjectStaticextendsProgrammingLanguageKind caseobjectDynamicextendsProgrammingLanguageKind
  • 9. Functional Programming Gems Function Composition Functions compose when theycause no side-effects Side-effects do notcompose scala>deffoo(something:String):String=s"foo($something)" scala>defbar(something:String):String=s"bar($something)" valcomposit=foo_composebar_ valreverseComposit=foo_andThenbar_ composit("anything") >foo(bar(anything)) reverseComposit("anything") >bar(foo(anything))
  • 10. Functional Programming Gems Combinators Applyhigh-order functions Glue for chainingfunctions Pure functions as domain invariants and behavior foundmap{foundLine=>partitions.success} | | Combinator High-orderfn Monadicchaining,viafor-comprehensions for{ | _<-quantityInvariant(quantity) _<-priceInvariant(price) (found,rest)<-productAlreadyExists(productId) }yield{/*dosomething*/}
  • 11. Functional Programming Gems Side Effects FP languages encourage isolatingside-effects from pure domain logic Known side-effects (notinsignigicant) 1. DBaccess 2. Logging 3. IO operations Example result.foreach{case(order,event)=> orderRepository.saveOrUpdate(order) }
  • 12. Functional Programming Gems More to cover Ad-hoc polymorphism viaTypeClasses Type-Lenses functionalupdates in your domain model
  • 14. Perception of State Domain state is effecivelymutable Can retain previous states Historyof whathappened In-place mutation are wrongfor domain model Theycombine state with time
  • 15. What's next Event Sourcing Everystate-modification on domain yields event Domain change is achieved byapplyingthe eventto the aggregate Eventstream, allthe events applied on domain
  • 16. What's next CQRS Commands execute operations on domain model Queries arbitraryviews of data Independentscalability
  • 17. What's next Memory Image and STM Application state in memory Application of events to currentstate on domain Enables transactions on memory
  • 18. Interesting Links 1. 2. 3. 4. 5. 6. 7. 8. PureFunction(Wikipedia) Referenctial Transparency(Wikipedia) Persistent Data Structure(Wikipedia) Presistend Data Structures and Managed References ADT, Product and SumTypes (Bob Harper, PFPL) SimpleMadeEasy(RichHickey) FunctionComposition(Wikipedia) Building Apps w/ Functional DomainModels (Debasish Ghosh)
  • 19. Thanks for your attention