Scala is one of the most commercially used successful programming languages in which functional programming is not only possible, but it is actively supported by language features, popular libraries, and many prominent advocates of functional programming.
In this webinar we look at one of the popular libraries of Scala - Cats Library. Cats contains a wide variety of functional programming tools and allows developers to pick the required ones. The majority of these tools are delivered in the form of type classes that we can apply to existing Scala types. It provides abstractions for functional programming in the Scala programming language.
New to Cats? No worries, Watch and explore in this webinar how amazing Cats and how to use Cats library for writing a more functional code in Scala.
[2024]Digital Global Overview Report 2024 Meltwater.pdf
Diving Into Scala Cats - Semigroups and Monoids
1. Diving Into Scala Cats -
Semigroups and
Monoids
Presented By: Mansi Babbar
Software Consultant
Knoldus Inc.
2. About Knoldus
Knoldus is a technology consulting firm with focus on modernizing the digital systems
at the pace your business demands.
DevOps
Functional. Reactive. Cloud Native
3. 01 Introduction to Scala Cats
02 Type Classes
03 Semigroups
04 Associativity Law of Semigroups
05 Limitations of Semigroups
Our Agenda
06 Demo of Semigroups
4. 07 Monoids
08 Why Monoids?
09 Associativity and Identity
Laws of Monoids
10 Demo of Monoids
Our Agenda
11 Conclusion
6. ● An abstraction for functional programming in
the Scala programming language.
● Cats contain a large variety of tools for
functional programming majorly in form of
type classes which we can apply to the
existing Scala types.
What is Cats?
8. What are Type Classes?
● Type classes are a pattern in
programming originating in Haskell.
● Allow us to extend existing libraries
with new functionality, without using
traditional inheritance, and also without
altering the original library source code.
10. Type Class :
● An API or interface that represents some functionality.
● Represented by a trait with at least one type parameter.
Type Class Components
11. Type Class Instances :
● Provide implementations of the type class for specific types.
● In Scala, we define instances by creating concrete implementations of the
type class and tagging them with the implicit keyword:
Type Class Components
12. Type Class Use :
● Any functionality which requires a type class instance to work.
● In Scala, this means any method that accepts instances of the type class as
implicit parameters.
● Cats provide utilities which make type classes a little bit easier to use, and
you may sometimes see these patterns in other libraries also.
● Type class can be used by creating Interface Objects.
Type Class Components
13. Interface Objects :
The simplest way of creating an interface that uses a type class is to place
methods in a singleton object:
Type Class Components
14. Interface Objects :
To use this object, we have to import any type class instances we care about
and then call the relevant method:
Type Class Components