SlideShare uma empresa Scribd logo
1 de 19
Baixar para ler 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

Mais conteúdo relacionado

Mais procurados

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
 

Mais procurados (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
 

Semelhante a 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
 

Semelhante a 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
 

Mais de 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
 

Mais de 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
 

Último

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
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
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
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
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
 
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
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
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
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
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
 
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
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAndikSusilo4
 
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
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 

Último (20)

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
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
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
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
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
 
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...
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
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
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
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
 
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
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & Application
 
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...
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 

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