•1 like•1,127 views

Report

Share

Download to read offline

Lecture demistifying monads. After talking a bit about Monoids and Functor I explain a functional design technics which is Monad through the refactoring of a JDBC code. Talk given at The Developper Conference in Porto Alegre in 2014 (http://www.thedevelopersconference.com.br), Code source of the presentation is in my github: https://github.com/toff63/monads-in-practice-tdc

Follow

- 1. Monads in Practice Christophe Marchal | Software Architect
- 2. A couple of links christophe.marchal@ilegra.com @toff63 http://github.com/toff63 http://francesbagual.net
- 3. Disclaimer
- 4. Manage complexity with Monad
- 5. Study Monads online is hard
- 6. Academic talks Functor Monoids Monads Category theory
- 8. Function Monoids Associative ( 1 + 2 ) + 3 = 1 + ( 2 + 3 ) InitiAl Value Result stay in the same category
- 10. Monoid
- 11. Functor Things that can be map over capacity BEHaviour map
- 12. Functor: Example
- 13. Functor: Example
- 14. Monads
- 16. Scenario F 1 F 2
- 17. sweet Monads Rules: function to create it
- 18. Broken Composition F 1 F 2 sweet
- 19. Monads Rules: You need a Functor F 1 map ( f 2 ) sweet
- 20. Scenario F 1 F 3 sweet
- 21. Problem: Nested Monad F 1 sweet map ( f 3 ) sweet
- 22. F 1 sweet Flatmap ( f 3 ) Monads Rules: You need a Flatmap
- 24. Business rule TRUE False age > 18 Authorized Not Authorized
- 26. What we want
- 27. Monad (?) Code
- 28. Trade-off More code than before Better API Easy to reuse Potential complexity Managed
- 29. Traditional Code
- 30. Side Effect Our method can return either a sequence either null
- 31. Exist ? TRUE False null ? Riendutout quelquechose
- 32. Encapsulating if null with Option
- 35. Business code
- 36. Side Effect Our method can return either an option [sequence] either throw an exception
- 37. Try! Success Failure Try to execute Gremio Inter
- 38. Encapsulating try/catch with Try
- 39. Encapsulating try/catch with Try
- 40. Code with Try
- 41. Business code
- 43. No silver bullet
- 44. Loan Pattern
- 45. Final Code
- 46. Conclusion ● NO IFs ● Border cases handled on demand ● More declarative types ● Highlight business code ● Easy to create ● More reusable code
- 47. Thank You! Christophe Marchal | Software Architect