Try and Future are abstractions in Scala that allow effects like exceptions and latency to be modeled and handled in a functional way. Try treats exceptions as effects by wrapping them and providing a pure functional interface. Future treats latency as an effect by delegating long-running computations to background threads. Both Try and Future are monads, meaning they support operations like flatMap that allow effects to be composed. This allows domain logic with potential effects to be written cleanly and resiliently.
non-strict functions, bottom and scala by-name parametersPhilip Schwarz
Download for perfect quality.
Non strict functions, bottom and scala by-name parameters - ‘a close look’, through the work of Runar Bjarnason, Paul Chiusano, Martin Odersky, Bill Venners, Lex Spoon, Alvin Alexander, Mark Lewis and Aleksandar Prokopec.
(download for flawless quality) Learn more about the canonical definition of the Applicative typeclass by looking at a great Haskell validation example by Chris Martin and Julie Moronuki - Then see it translated to Scala.
Scala code: https://github.com/philipschwarz/applicative-functor-part-2-scala
--- Errata ---
Slide #41: the definition of the right shark operator contains a defect - see https://twitter.com/philip_schwarz/status/1416127396659478539
(download for flawless quality) A brief introduction to unison, the exciting and innovative new functional programming language.
Wholly based on a talk by Paul Chiusano.
Writer Monad for logging execution of functionsPhilip Schwarz
download for better quality - Learn how to use the Writer monad to log (trace) the execution of functions through the work of Bartosz Milewski and Alvin Alexander
Refactoring: A First Example - Martin Fowler’s First Example of Refactoring, ...Philip Schwarz
Follow in the footsteps of refactoring guru Martin Fowler as he improves the design of a program in a simple yet instructive refactoring example whose JavaScript code and associated refactoring is herein adapted to Scala.
Based on the second edition of ‘the’ Refactoring book.
Here is a github repository with the whole refactoring, from start to finish, following the steps seen in the slides https://github.com/philipschwarz/refactoring-a-first-example-scala
non-strict functions, bottom and scala by-name parametersPhilip Schwarz
Download for perfect quality.
Non strict functions, bottom and scala by-name parameters - ‘a close look’, through the work of Runar Bjarnason, Paul Chiusano, Martin Odersky, Bill Venners, Lex Spoon, Alvin Alexander, Mark Lewis and Aleksandar Prokopec.
(download for flawless quality) Learn more about the canonical definition of the Applicative typeclass by looking at a great Haskell validation example by Chris Martin and Julie Moronuki - Then see it translated to Scala.
Scala code: https://github.com/philipschwarz/applicative-functor-part-2-scala
--- Errata ---
Slide #41: the definition of the right shark operator contains a defect - see https://twitter.com/philip_schwarz/status/1416127396659478539
(download for flawless quality) A brief introduction to unison, the exciting and innovative new functional programming language.
Wholly based on a talk by Paul Chiusano.
Writer Monad for logging execution of functionsPhilip Schwarz
download for better quality - Learn how to use the Writer monad to log (trace) the execution of functions through the work of Bartosz Milewski and Alvin Alexander
Refactoring: A First Example - Martin Fowler’s First Example of Refactoring, ...Philip Schwarz
Follow in the footsteps of refactoring guru Martin Fowler as he improves the design of a program in a simple yet instructive refactoring example whose JavaScript code and associated refactoring is herein adapted to Scala.
Based on the second edition of ‘the’ Refactoring book.
Here is a github repository with the whole refactoring, from start to finish, following the steps seen in the slides https://github.com/philipschwarz/refactoring-a-first-example-scala
‘go-to’ general-purpose sequential collections -from Java To ScalaPhilip Schwarz
The simple idea of this slide deck is that it collects in a single place quite a bit of information that can be used to gain a basic understanding of some key differences between the ’goto’ sequential collections of Java and Scala.
Errata:
* the twitter handle of Daniel Westheide is @kaffeecoder and not @cafeecoder
* on slide 35, the numbers 215, 220, 225 and 230, should be 2^15, 2^20, 2^25 and 2^30 respectively
* on slide 54, the bottom left node should be green rather than black
Understand the expression problem
See Haskell and Scala code illustrating the problem
Learn how FP typeclasses can be used to solve the problem
See the Haskell solution to the problem and a translation into Scala
Part 2
Scala 3 by Example - Algebraic Data Types for Domain Driven Design - Part 1Philip Schwarz
slides can look grainy and/or out of focus when seen on slideshare - download for flawless quality - Based on Scott Wlaschin’s great book 'Domain Modeling Made Functional' and on Martin Odersky's talk 'A Tour of Scala 3'.
Game of Life - Polyglot FP - Haskell, Scala, Unison - Part 2 - with minor cor...Philip Schwarz
(download for picture-perfect quality) Follow along as the impure functions in the Game of Life are translated from Haskell into Scala, deepening you understanding of the IO monad in the process.
This is simply a copy of the original with an error corrected on slides 3 and 52, which were supposed to show Scala code and instead showed the Haskell equivalent! Plus removal of a few minor aesthetic imperfections.
Original: https://www.slideshare.net/pjschwarz/game-of-life-polyglot-fp-haskell-scala-unison-part-2
Refactoring: A First Example - Martin Fowler’s First Example of Refactoring, ...Philip Schwarz
Follow in the footsteps of refactoring guru Martin Fowler as he improves the design of a program in a simple yet instructive refactoring example whose JavaScript code and associated refactoring is herein adapted to Java.
Based on the second edition of ‘the’ Refactoring book.
In the process, we’ll be using the following Java language features incorporated into long-term support (LTS) version JDK 17 (the previous LTS version being JDK 11):
Text blocks (JDK 15)
Records (JDK 16)
Sealed interfaces (JDK 17)
Here is a github repository with the whole refactoring, from start to finish, following the steps seen in the slides https://github.com/philipschwarz/refactoring-a-first-example-java
Download for better quality - Learn about the composition of effectful functions through the work of Bartosz Milewski, Rob Norris, Rúnar Bjarnason and Debasish Ghosh.
My summary of Natural Transformations based on definitions found in an introductory book on Category theory and on Bartosz Milewski’s great lecture on the subject.
NOTE: Download for better quality.
Esoft Metro Campus - Certificate in c / c++ programmingRasan Samarasinghe
Esoft Metro Campus - Certificate in java basics
(Template - Virtusa Corporate)
Contents:
Structure of a program
Variables & Data types
Constants
Operators
Basic Input/output
Control Structures
Functions
Arrays
Character Sequences
Pointers and Dynamic Memory
Unions
Other Data Types
Input/output with files
Searching
Sorting
Introduction to data structures
In computer programming, code smell is any symptom in the source code of a program that possibly indicates a deeper problem. Code smells are usually not bugs—they are not technically incorrect and do not currently prevent the program from functioning. Instead, they indicate weaknesses in design that may be slowing down development or increasing the risk of bugs or failures in the future.
Video and more content at fsharpforfunandprofit.com/pbt
"The lazy programmer's guide to writing 1000's of tests: An introduction to property based testing"
We are all familiar with example-based testing, as typified by TDD and BDD. Property-based testing takes a very different approach, where a single test is run hundreds of times with randomly generated inputs.
Property-based testing is a great way to find edge cases, and also helps you to understand and document the behaviour of your code under all conditions.
This talk will introduce property-based testing and show how it works, and why you should consider adding it to your arsenal of testing tools.
Tagless Final Encoding - Algebras and Interpreters and also ProgramsPhilip Schwarz
Tagless Final Encoding - Algebras and Interpreters and also Programs - An introduction, through the work of Gabriel Volpe.
Slide deck home: http://fpilluminated.com/assets/tagless-final-encoding-algebras-interpreters-and-programs.html
‘go-to’ general-purpose sequential collections -from Java To ScalaPhilip Schwarz
The simple idea of this slide deck is that it collects in a single place quite a bit of information that can be used to gain a basic understanding of some key differences between the ’goto’ sequential collections of Java and Scala.
Errata:
* the twitter handle of Daniel Westheide is @kaffeecoder and not @cafeecoder
* on slide 35, the numbers 215, 220, 225 and 230, should be 2^15, 2^20, 2^25 and 2^30 respectively
* on slide 54, the bottom left node should be green rather than black
Understand the expression problem
See Haskell and Scala code illustrating the problem
Learn how FP typeclasses can be used to solve the problem
See the Haskell solution to the problem and a translation into Scala
Part 2
Scala 3 by Example - Algebraic Data Types for Domain Driven Design - Part 1Philip Schwarz
slides can look grainy and/or out of focus when seen on slideshare - download for flawless quality - Based on Scott Wlaschin’s great book 'Domain Modeling Made Functional' and on Martin Odersky's talk 'A Tour of Scala 3'.
Game of Life - Polyglot FP - Haskell, Scala, Unison - Part 2 - with minor cor...Philip Schwarz
(download for picture-perfect quality) Follow along as the impure functions in the Game of Life are translated from Haskell into Scala, deepening you understanding of the IO monad in the process.
This is simply a copy of the original with an error corrected on slides 3 and 52, which were supposed to show Scala code and instead showed the Haskell equivalent! Plus removal of a few minor aesthetic imperfections.
Original: https://www.slideshare.net/pjschwarz/game-of-life-polyglot-fp-haskell-scala-unison-part-2
Refactoring: A First Example - Martin Fowler’s First Example of Refactoring, ...Philip Schwarz
Follow in the footsteps of refactoring guru Martin Fowler as he improves the design of a program in a simple yet instructive refactoring example whose JavaScript code and associated refactoring is herein adapted to Java.
Based on the second edition of ‘the’ Refactoring book.
In the process, we’ll be using the following Java language features incorporated into long-term support (LTS) version JDK 17 (the previous LTS version being JDK 11):
Text blocks (JDK 15)
Records (JDK 16)
Sealed interfaces (JDK 17)
Here is a github repository with the whole refactoring, from start to finish, following the steps seen in the slides https://github.com/philipschwarz/refactoring-a-first-example-java
Download for better quality - Learn about the composition of effectful functions through the work of Bartosz Milewski, Rob Norris, Rúnar Bjarnason and Debasish Ghosh.
My summary of Natural Transformations based on definitions found in an introductory book on Category theory and on Bartosz Milewski’s great lecture on the subject.
NOTE: Download for better quality.
Esoft Metro Campus - Certificate in c / c++ programmingRasan Samarasinghe
Esoft Metro Campus - Certificate in java basics
(Template - Virtusa Corporate)
Contents:
Structure of a program
Variables & Data types
Constants
Operators
Basic Input/output
Control Structures
Functions
Arrays
Character Sequences
Pointers and Dynamic Memory
Unions
Other Data Types
Input/output with files
Searching
Sorting
Introduction to data structures
In computer programming, code smell is any symptom in the source code of a program that possibly indicates a deeper problem. Code smells are usually not bugs—they are not technically incorrect and do not currently prevent the program from functioning. Instead, they indicate weaknesses in design that may be slowing down development or increasing the risk of bugs or failures in the future.
Video and more content at fsharpforfunandprofit.com/pbt
"The lazy programmer's guide to writing 1000's of tests: An introduction to property based testing"
We are all familiar with example-based testing, as typified by TDD and BDD. Property-based testing takes a very different approach, where a single test is run hundreds of times with randomly generated inputs.
Property-based testing is a great way to find edge cases, and also helps you to understand and document the behaviour of your code under all conditions.
This talk will introduce property-based testing and show how it works, and why you should consider adding it to your arsenal of testing tools.
Tagless Final Encoding - Algebras and Interpreters and also ProgramsPhilip Schwarz
Tagless Final Encoding - Algebras and Interpreters and also Programs - An introduction, through the work of Gabriel Volpe.
Slide deck home: http://fpilluminated.com/assets/tagless-final-encoding-algebras-interpreters-and-programs.html
I am Susan C. I am an Instant DBMS Homework Expert at databasehomeworkhelp.com. I hold a Master’s Degree in Programming, from Leeds, UK. I have been helping students with their homework for the past 9 years. I solve homework related to Instant DBMS.
Visit databasehomeworkhelp.com or email info@databasehomeworkhelp.com. You can also call on +1 678 648 4277 for any assistance with Instant DBMS Homework.
Patterns and Anti-patterns
How to learn design patterns?
Categories of GoF patterns
The Fundamental theorem of software engineering
Real-world problems and how design patterns solve them with GoF structural patterns
LESSON 4: INTRODUCING FUNCTIONS AND MODULAR DESIGN
Learn about Functions in Python. Advantages and disadvantages of functions. Introduction to Modular design. Local and Global Variables and their use. Passing parameters. What are arguments? Big questions: Evolution vs Intelligent design in light of functions (and modular design). A closer look at Robotics and advances in this field. Challenges and tasks including with solutions. Suggested research/HW and YouTube video recommendations. A note on Python’s built in functions.
Top 7 Angular Best Practices to Organize Your Angular AppKaty Slemon
Learn about Angular best practices to improve the performance of your existing Angular application. Tried and tested clean code checklist for your Angular app.
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidPhilip Schwarz
The subject of this deck is the small Print[A] program in the following blog post by Noel Welsh: https://www.inner-product.com/posts/direct-style-effects/.
Keywords: "direct-style", "context function", "context functions", "algebraic effect", "algebraic effects", "scala", "effect system", "effect systems", "effect", "side effect", "composition", "fp", "functional programming"
Folding Cheat Sheet #4 - fourth in a seriesPhilip Schwarz
For functions that can be defined both as an instance of a right fold and as an instance of a left fold, one may be more efficient than the other.
Let's look at the example of a function 'decimal' that converts a list of digits into the corresponding decimal number.
Erratum: it has been pointed out that it is possible to define the zip function using a right fold (see slide 5).
A sighting of traverseFilter and foldMap in Practical FP in ScalaPhilip Schwarz
Slide deck home: http://fpilluminated.com/assets/sighting-of-scala-cats-traverseFilter-and-foldMap-in-practical-fp-in-scala.html.
Download PDF for perfect image quality.
A sighting of sequence function in Practical FP in ScalaPhilip Schwarz
Slide deck home: http://fpilluminated.com/assets/sighting-of-scala-cats-sequence-function-in-practical-fp-in-scala.html.
Download PDF for perfect image quality.
This talk was presented on Aug 3rd 2023 during the Scala in the City event a ITV in London https://www.meetup.com/scala-in-the-city/events/292844968/
Visit the following for a description, slideshow, all slides with transcript, pdf, github repo, and eventually a video recording: http://fpilluminated.com/assets/n-queens-combinatorial-puzzle-meets-cats.html
At the centre of this talk is the N-Queens combinatorial puzzle. The reason why this puzzle features in the Scala book and functional programming course by Martin Odersky (the language’s creator), is that such puzzles are a particularly suitable application area of 'for comprehensions'.
We’ll start by (re)acquainting ourselves with the puzzle, and seeing the role played in it by permutations. Next, we’ll see how, when wanting to visualise candidate puzzle solutions, Cats’ monoidal functions fold and foldMap are a great fit for combining images.
While we are all very familiar with the triad providing the bread, butter and jam of functional programming, i.e. map, filter and fold, not everyone knows about the corresponding functions in Cats’ monadic variant of the triad, i.e. mapM, filterM and foldM, which we are going to learn about next.
As is often the case in functional programming, the traverse function makes an appearance, and we shall grab the opportunity to point out the symmetry that exists in the interrelation of flatMap / foldMap / traverse and flatten / fold / sequence.
Armed with an understanding of foldM, we then look at how such a function can be used to implement an iterative algorithm for the N-Queens puzzle.
The talk ends by pointing out that the iterative algorithm is smarter than the recursive one, because it ‘remembers’ where it has already placed previous queens.
Kleisli composition, flatMap, join, map, unit - implementation and interrelat...Philip Schwarz
Kleisli composition, flatMap, join, map, unit. A study/memory aid, to help learn/recall their implementation/interrelation.
Version 2, updated for Scala 3
Nat, List and Option Monoids -from scratch -Combining and Folding -an examplePhilip Schwarz
Nat, List and Option Monoids, from scratch. Combining and Folding: an example.
This is a new version of the original which has some cosmetic changes and a new 7th slide which only differs from slide 6 in that it defines the fold function in terms of the foldRight function.
Code: https://github.com/philipschwarz/nat-list-and-option-monoids-from-scratch-combining-and-folding-an-example
Nat, List and Option Monoids -from scratch -Combining and Folding -an examplePhilip Schwarz
Nat, List and Option Monoids, from scratch. Combining and Folding: an example.
Code: https://github.com/philipschwarz/nat-list-and-option-monoids-from-scratch-combining-and-folding-an-example
The Sieve of Eratosthenes - Part II - Genuine versus Unfaithful Sieve - Haske...Philip Schwarz
When I posted the deck for Part 1 to the Scala users forum, Odd Möller linked to a paper titled "The Genuine Sieve of Eratosthenes", which speaks of the Unfaithful Sieve.
Part 2 is based on that paper and on Richard Bird's faithful Haskell implementation of the Sieve, which we translate into Scala.
Scala code for Richard Bird's infinite primes Haskell program: https://github.com/philipschwarz/sieve-of-eratosthenes-part-2-scala
Sum and Product Types -The Fruit Salad & Fruit Snack Example - From F# to Ha...Philip Schwarz
Sum and Product Types -The Fruit Salad & Fruit Snack Example - From F# to Haskell, Scala and Java.
Inspired by the example in Scott Wlaschin’s F# book: Domain Modeling Made Functional.
Download for better results.
Java 19 Code: https://github.com/philipschwarz/fruit-salad-and-fruit-snack-ADT-example-java
Jordan Peterson - The pursuit of meaning and related ethical axiomsPhilip Schwarz
I have only recently become aware of the work of Jordan Peterson. Because I am finding it so interesting, I hope that the following small collection of excerpts from some of his writings and speeches might entice any fellow latecomers to find out more about his work. See below for my own summary of some of the subjects touched upon in these slides.
Download for best results.
Understanding Globus Data Transfers with NetSageGlobus
NetSage is an open privacy-aware network measurement, analysis, and visualization service designed to help end-users visualize and reason about large data transfers. NetSage traditionally has used a combination of passive measurements, including SNMP and flow data, as well as active measurements, mainly perfSONAR, to provide longitudinal network performance data visualization. It has been deployed by dozens of networks world wide, and is supported domestically by the Engagement and Performance Operations Center (EPOC), NSF #2328479. We have recently expanded the NetSage data sources to include logs for Globus data transfers, following the same privacy-preserving approach as for Flow data. Using the logs for the Texas Advanced Computing Center (TACC) as an example, this talk will walk through several different example use cases that NetSage can answer, including: Who is using Globus to share data with my institution, and what kind of performance are they able to achieve? How many transfers has Globus supported for us? Which sites are we sharing the most data with, and how is that changing over time? How is my site using Globus to move data internally, and what kind of performance do we see for those transfers? What percentage of data transfers at my institution used Globus, and how did the overall data transfer performance compare to the Globus users?
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...Juraj Vysvader
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I didn't get rich from it but it did have 63K downloads (powered possible tens of thousands of websites).
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxrickgrimesss22
Discover the essential features to incorporate in your Winzo clone app to boost business growth, enhance user engagement, and drive revenue. Learn how to create a compelling gaming experience that stands out in the competitive market.
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Globus
The Earth System Grid Federation (ESGF) is a global network of data servers that archives and distributes the planet’s largest collection of Earth system model output for thousands of climate and environmental scientists worldwide. Many of these petabyte-scale data archives are located in proximity to large high-performance computing (HPC) or cloud computing resources, but the primary workflow for data users consists of transferring data, and applying computations on a different system. As a part of the ESGF 2.0 US project (funded by the United States Department of Energy Office of Science), we developed pre-defined data workflows, which can be run on-demand, capable of applying many data reduction and data analysis to the large ESGF data archives, transferring only the resultant analysis (ex. visualizations, smaller data files). In this talk, we will showcase a few of these workflows, highlighting how Globus Flows can be used for petabyte-scale climate analysis.
Large Language Models and the End of ProgrammingMatt Welsh
Talk by Matt Welsh at Craft Conference 2024 on the impact that Large Language Models will have on the future of software development. In this talk, I discuss the ways in which LLMs will impact the software industry, from replacing human software developers with AI, to replacing conventional software with models that perform reasoning, computation, and problem-solving.
We describe the deployment and use of Globus Compute for remote computation. This content is aimed at researchers who wish to compute on remote resources using a unified programming interface, as well as system administrators who will deploy and operate Globus Compute services on their research computing infrastructure.
GraphSummit Paris - The art of the possible with Graph TechnologyNeo4j
Sudhir Hasbe, Chief Product Officer, Neo4j
Join us as we explore breakthrough innovations enabled by interconnected data and AI. Discover firsthand how organizations use relationships in data to uncover contextual insights and solve our most pressing challenges – from optimizing supply chains, detecting fraud, and improving customer experiences to accelerating drug discoveries.
Check out the webinar slides to learn more about how XfilesPro transforms Salesforce document management by leveraging its world-class applications. For more details, please connect with sales@xfilespro.com
If you want to watch the on-demand webinar, please click here: https://www.xfilespro.com/webinars/salesforce-document-management-2-0-smarter-faster-better/
Navigating the Metaverse: A Journey into Virtual Evolution"Donna Lenk
Join us for an exploration of the Metaverse's evolution, where innovation meets imagination. Discover new dimensions of virtual events, engage with thought-provoking discussions, and witness the transformative power of digital realms."
Unleash Unlimited Potential with One-Time Purchase
BoxLang is more than just a language; it's a community. By choosing a Visionary License, you're not just investing in your success, you're actively contributing to the ongoing development and support of BoxLang.
Listen to the keynote address and hear about the latest developments from Rachana Ananthakrishnan and Ian Foster who review the updates to the Globus Platform and Service, and the relevance of Globus to the scientific community as an automation platform to accelerate scientific discovery.
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns
Unlocking Business Potential: Tailored Technology Solutions by Prosigns
Discover how Prosigns, a leading technology solutions provider, partners with businesses to drive innovation and success. Our presentation showcases our comprehensive range of services, including custom software development, web and mobile app development, AI & ML solutions, blockchain integration, DevOps services, and Microsoft Dynamics 365 support.
Custom Software Development: Prosigns specializes in creating bespoke software solutions that cater to your unique business needs. Our team of experts works closely with you to understand your requirements and deliver tailor-made software that enhances efficiency and drives growth.
Web and Mobile App Development: From responsive websites to intuitive mobile applications, Prosigns develops cutting-edge solutions that engage users and deliver seamless experiences across devices.
AI & ML Solutions: Harnessing the power of Artificial Intelligence and Machine Learning, Prosigns provides smart solutions that automate processes, provide valuable insights, and drive informed decision-making.
Blockchain Integration: Prosigns offers comprehensive blockchain solutions, including development, integration, and consulting services, enabling businesses to leverage blockchain technology for enhanced security, transparency, and efficiency.
DevOps Services: Prosigns' DevOps services streamline development and operations processes, ensuring faster and more reliable software delivery through automation and continuous integration.
Microsoft Dynamics 365 Support: Prosigns provides comprehensive support and maintenance services for Microsoft Dynamics 365, ensuring your system is always up-to-date, secure, and running smoothly.
Learn how our collaborative approach and dedication to excellence help businesses achieve their goals and stay ahead in today's digital landscape. From concept to deployment, Prosigns is your trusted partner for transforming ideas into reality and unlocking the full potential of your business.
Join us on a journey of innovation and growth. Let's partner for success with Prosigns.
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Globus
Large Language Models (LLMs) are currently the center of attention in the tech world, particularly for their potential to advance research. In this presentation, we'll explore a straightforward and effective method for quickly initiating inference runs on supercomputers using the vLLM tool with Globus Compute, specifically on the Polaris system at ALCF. We'll begin by briefly discussing the popularity and applications of LLMs in various fields. Following this, we will introduce the vLLM tool, and explain how it integrates with Globus Compute to efficiently manage LLM operations on Polaris. Attendees will learn the practical aspects of setting up and remotely triggering LLMs from local machines, focusing on ease of use and efficiency. This talk is ideal for researchers and practitioners looking to leverage the power of LLMs in their work, offering a clear guide to harnessing supercomputing resources for quick and effective LLM inference.
OpenMetadata Community Meeting - 5th June 2024OpenMetadata
The OpenMetadata Community Meeting was held on June 5th, 2024. In this meeting, we discussed about the data quality capabilities that are integrated with the Incident Manager, providing a complete solution to handle your data observability needs. Watch the end-to-end demo of the data quality features.
* How to run your own data quality framework
* What is the performance impact of running data quality frameworks
* How to run the test cases in your own ETL pipelines
* How the Incident Manager is integrated
* Get notified with alerts when test cases fail
Watch the meeting recording here - https://www.youtube.com/watch?v=UbNOje0kf6E
2. Functional thinking and implementing with pure functions is a great engineering discipline for your domain model. But you also
need language support that helps build models that are responsive to failures, scales well with increasing load, and delivers a
nice experience to users. Chapter 1 referred to this characteristic as being reactive, and identified the following two aspects that
you need to address in order to make your model reactive:
• Manage failures, also known as design for failure
• Minimize latency by delegating long-running processes to background threads without blocking the main thread of
execution
In this section, you’ll see how Scala offers abstractions that help you address both of these issues. You can manage exceptions
and latency as effects that compose along with the other pure abstractions of your domain model. An effect adds capabilities
to your computation so that you don’t need to use side effects to model them. The sidebar “What is an effectful computation?”
details what I mean.
Managing exceptions is a key component of reactive models—you need to ensure that a failing component doesn’t bring down
the entire application. And managing latency is another key aspect that you need to take care of—unbounded latency through
blocking calls in your application is a severe antipattern of good user experience. Luckily, Scala covers both of them by
providing abstractions as part of the standard library.
What is an effectful computation?
In functional programming, an effect adds some capabilities to a computation. And because we’re dealing with a statically typed
language, these capabilities come in the form of more power from the type system. An effect is modeled usually in the form of a
type constructor that constructs types with these additional capabilities.
Say you have any type A and you’d like to add the capability of aggregation, so that you can treat a collection of A as a separate
type. You do this by constructing a type List[A] (for which the corresponding type constructor is List), which adds the effect of
aggregation on A. Similarly, you can have Option[A] that adds the capability of optionality for the type A.
In the next section, you’ll learn how to use type constructors such as Try and Future to model the effects of exceptions and
latency, respectively. In chapter 4 we’ll discuss more advanced effect handling using applicatives and monads.
@debasishg
Debasish Ghosh
3. 2.6.1 Managing effects
When we’re talking about exceptions, latency, and so forth in the context of making your model reactive, you must be
wondering how to adapt these concepts into the realm of functional programming. Chapter 1 called these side effects and
warned you about the cast of gloom that they bring to your pure domain logic. Now that we’re talking about managing them to
make our models reactive, how should you treat them as part of your model so that they can be composed in a referentially
transparent way along with the other domain elements?
In Scala, you treat them as effects, in the sense that you abstract them within containers that expose functional interfaces
to the world. The most common example of treating exceptions as effects in Scala is the Try abstraction, which you saw
earlier. Try provides a sum type, with one of the variants (Failure) abstracting the exception that your computation can
raise. Try wraps the effect of exceptions within itself and provides a purely functional interface to the user. In the more
general sense of the term, Try is a monad. There are some other examples of effect handling as well. Latency is another
example, which you can treat as an effect—instead of exposing the model to the vagaries of unbounded latency, you use
constructs such as Future that act as abstractions to manage latency. You’ll see some examples shortly.
The concept of a monad comes from category theory. This book doesn’t go into the theoretical underpinnings of a monad as a
category. It focuses more on monads as abstract computations that help you mimic the effects of typically impure actions
such as exceptions, I/O, continuations, and so forth while providing a functional interface to your users. And we’ll limit
ourselves to the monadic implementations that some of the Scala abstractions such as Try and Future offer. The only
takeaway on what a monad does in the context of functional and reactive domain modeling is that it abstracts effects and lets
you play with a pure functional interface that composes nicely with the other components.
@debasishg
Debasish Ghosh
5. def calculateInterest[A <: SavingsAccount](account: A, balance: BigDecimal): Try[BigDecimal] = ???
def getCurrencyBalance[A <: SavingsAccount](account: A): Try[BigDecimal] = ???
def calculateNetAssetValue[A <: SavingsAccount](account: A, ccyBalance: BigDecimal, interest: BigDecimal): Try[BigDecimal] = ???
val account: SavingsAccount = ???
val result: Try[BigDecimal] = for {
balance ⃪ getCurrencyBalance(account)
interest ⃪ calculateInterest(account, balance)
value ⃪ calculateNetAssetValue(account, balance, interest)
} yield value
result match {
case Success(v) => ??? // .. success
case Failure(ex) => ??? // .. failure
}
Listing 2.13 shows three functions, each of which can fail in some circumstances. We make that fact loud and clear—instead of BigDecimal, these
functions return Try[BigDecimal].
You’ve seen Try before and know how it abstracts exceptions within your Scala code. Here, by returning a Try, the function makes it explicit that it can
fail. If all is good and happy, you get the result in the Success branch of the Try, and if there’s an exception, then you get it from the Failure variant.
The most important point to note is that the exception never escapes from the Try as an unwanted side effect to pollute your compositional code. Thus
you’ve achieved the first promise of the two-pronged strategy of failure management in Scala: being explicit about the fact that this function can fail.
But what about the promise of compositionality? Yes, Try also gives you
that by being a monad and offering a lot of higher-order functions. Here’s the
flatMap method of Try that makes it a monad and helps you compose
with other functions that may fail:
def flatMap[U](f: T => Try[U]): Try[U]
You saw earlier how flatMap binds together computations and helps you
write nice, sequential for-comprehensions without forgoing the goodness of
expression-oriented evaluation. You can get the same goodness with Try
and compose code that may fail:
This code handles all exceptions, composes nicely, and expresses the intent of the code in a clear and succinct manner. This is what you get when you
have powerful language abstractions to back your domain model. Try is the abstraction that handles the exceptions, and flatMap is the secret sauce
that lets you program through the happy path. So you can now have domain model elements that can throw exceptions—just use the Try abstraction for
managing the effects and you can make your code resilient to failures.
@debasishg
Debasish Ghosh
Functional and Reactive
Domain Modeling
Managing Failures
6. Managing Latency
def calculateInterest[A <: SavingsAccount](account: A, balance: BigDecimal):Future[BigDecimal] = ???
def getCurrencyBalance[A <: SavingsAccount](account: A): Future[BigDecimal] = ???
def calculateNetAssetValue[A <: SavingsAccount](account: A, ccyBalance: BigDecimal, interest: BigDecimal): Future[BigDecimal] = ???
val account: SavingsAccount = ???
implicit val ec: ExecutionContext = ???
val result: Future[BigDecimal] = for {
balance ⃪ getCurrencyBalance(account)
interest ⃪ calculateInterest(account, balance)
value ⃪ calculateNetAssetValue(account, balance, interest)
} yield value
result onComplete {
case Success(v) => ??? //.. success
case Failure(ex) => ??? //.. failure
}
Just as Try manages exceptions using effects, another abstraction in the Scala library called Future helps you manage latency as an effect. What does that
mean? Reactive programming suggests that our model needs to be resilient to variations in latency, which may occur because of increased load on the system
or network delays or many other factors beyond the control of the implementer. To provide an acceptable user experience with respect to response time, our
model needs to guarantee some bounds on the latency.
The idea is simple: Wrap your long-running computations in a Future. The computation will be delegated to a background thread, without blocking
the main thread of execution. As a result, the user experience won’t suffer, and you can make the result of the computation available to the user whenever you
have it. Note that this result can also be a failure, in case the computation failed—so Future handles both latency and exceptions as effects.
@debasishg
Debasish Ghosh
Functional and Reactive
Domain Modeling
Future is also a monad, just like Try, and has the flatMap method
that helps you bind your domain logic to the happy path of
computation… imagine that the functions you wrote in listing 2.13
involve network calls, and thus there’s always potential for long latency
associated with each of them. As I suggested earlier, let’s make this explicit
to the user of our API and make each of the functions return Future:
By using flatMap, you can now compose the functions sequentially to yield another Future. The net effect is that the entire computation is delegated to
a background thread, and the main thread of execution remains free. Better user experience is guaranteed, and you’ve implemented what the reactive
principles talk about—systems being resilient to variations in network latency. The following listing demonstrates the sequential composition of futures in
Scala.
Here, result is also a Future, and you can plug in callbacks for the success and failure paths of the completed Future. If the Future completes
successfully, you have the net asset value that you can pass on to the client. If it fails, you can get that exception as well and implement custom
processing of the exception.
7. def calculateInterest[A <: SavingsAccount](account: A, balance: BigDecimal): Try[BigDecimal] = ???
def getCurrencyBalance[A <: SavingsAccount](account: A): Try[BigDecimal] = ???
def calculateNetAssetValue[A <: SavingsAccount](account: A, ccyBalance: BigDecimal, interest: BigDecimal): Try[BigDecimal] = ???
val account: SavingsAccount = ???
val result: Try[BigDecimal] = for {
balance <- getCurrencyBalance(account)
interest <- calculateInterest(account, balance)
value <- calculateNetAssetValue(account, balance, interest)
} yield value
result match {
case Success(v) => ??? // .. success
case Failure(ex) => ??? // .. failure
}
def calculateInterest[A <: SavingsAccount](account: A, balance: BigDecimal): Future[BigDecimal] = ???
def getCurrencyBalance[A <: SavingsAccount](account: A): Future[BigDecimal] = ???
def calculateNetAssetValue[A <: SavingsAccount](account: A, ccyBalance: BigDecimal, interest: BigDecimal): Future[BigDecimal] = ???
val account: SavingsAccount = ???
implicit val ec: ExecutionContext = ???
val result: Future[BigDecimal] = for {
balance <- getCurrencyBalance(account)
interest <- calculateInterest(account, balance)
value <- calculateNetAssetValue(account, balance, interest)
} yield value
result onComplete {
case Success(v) => ??? //.. success
case Failure(ex) => ??? //.. failure
}
Managing Failures
Managing Latency
8. That was great. Functional and Reactive Domain Modeling is a very nice book.
I’ll leave you with a question: are Try and Future lawful monads? See the following for
an introduction to monad laws and how to check if they are being obeyed:
https://www.slideshare.net/pjschwarz/monad-laws-must-be-checked-107011209
@philip_schwarz
Monad Laws Must be Checked