Introduction to ScalaZ
Prabhat Kashyap
Trainee Software Consultant
Knoldus Software LLP
What is Scalaz
● It is just another library for Scala.
What is Scalaz
● It is just another library for Scala.
● Scalaz is purely functional library.
What is Scalaz
● It is just another library for Scala.
● Scalaz is purely functional library.
● It provides new functions.
What is Scalaz
● It is just another library for Scala.
● Scalaz is purely functional library.
● It provides new functions.
● It’s an open source project
(https://github.com/scalaz/scalaz)
Why new library?
Whats wrong with this code:
val internInProject = Map(
"Prabhat" -> "ScalaGeek",
"Kunal" -> "FitFyles",
"Himani" -> "FitFyles"
)
def isInternFromProject(project: String, intern:
String): Boolean =
(internInProject get intern) == project
Whats wrong with this code:
val internInProject = Map(
"Prabhat" -> "ScalaGeek",
"Kunal" -> "FitFyles",
"Himani" -> "FitFyles"
)
def isInternFromProject(project: String, intern:
String): Boolean =
(internInProject get intern) == project
== is not typesafe here
IsInternFromProject will always return false
Let’s try one more
val intern1 = Map(
"Prabhat" -> Map("scalageek" -> 10, "FitFyles" -> 1),
"Aarwee" -> Map("FitFyles" -> 6, "ScalaGeek" -> 3),
"Deepti" -> Map("FitFyles" -> 11)
)
val intern2 = Map(
"Prabhat" -> Map("scalageek" -> 3)
)
Now you can write a complex code with map functions
Let’s try one more
val intern1 = Map(
"Prabhat" -> Map("scalageek" -> 10, "FitFyles" -> 1),
"Aarwee" -> Map("FitFyles" -> 6, "ScalaGeek" -> 3),
"Deepti" -> Map("FitFyles" -> 11)
)
val intern2 = Map(
"Prabhat" -> Map("scalageek" -> 3)
)
Or you can use |+|
val combinedResult = (intern1 |+| intern2)
Let’s try one more
val intern1 = Map(
"Prabhat" -> Map("scalageek" -> 10, "FitFyles" -> 1),
"Aarwee" -> Map("FitFyles" -> 6, "ScalaGeek" -> 3),
"Deepti" -> Map("FitFyles" -> 11)
)
val intern2 = Map(
"Prabhat" -> Map("scalageek" -> 3)
)
Or you can use |+|
val combinedResult = (intern1 |+| intern2)
Map(
"Prabhat" -> Map("scalageek" -> 13, "FitFyles" -> 1),
"Aarwee" -> Map("FitFyles" -> 6, "ScalaGeek" -> 3),
"Deepti" -> Map("FitFyles" -> 11))
And Combined Result will be
Why ScalaZ
● Scalaz is a library for doing pure Functional
Programming in Scala.
Why ScalaZ
● Scalaz is a library for doing pure Functional
Programming in Scala.
● Scalaz does not encourage subtyping—instead it
espouses typeclass-based ad hoc polymorphism
using higher order functions.
Why ScalaZ
● Scalaz is a library for doing pure Functional
Programming in Scala.
● Scalaz does not encourage subtyping—instead it
espouses typeclass-based ad hoc polymorphism
using higher order functions.
● Scalaz comes with a lot of built in typeclasses and
encourages you to build your own.
Today we only be looking at
Scalaz Typeclasses
ScalaZ Typeclasses
● Equal[A] typeclass
ScalaZ Typeclasses
● Equal[A] typeclass
● Order
ScalaZ Typeclasses
● Equal[A] typeclass
● Order
● Enum
ScalaZ Typeclasses
● Equal[A] typeclass
● Order
● Enum
ScalaZ Typeclasses
● Equal[A] typeclass
● Order
● Enum
● Options
ScalaZ Typeclasses
● Equal[A] typeclass
● Order
● Enum
● Options
ScalaZ Typeclasses
● Equal[A] typeclass
● Order
● Enum
● Options
● Validation
ScalaZ Typeclasses
● Equal[A] typeclass
● Order
● Enum
● Options
● Validation
Questions?
References
● Wikipedia
● http://eed3si9n.com/
● Youtube
– Scalaz Presentation - Nick Partridge
– Introduction to Scalaz - Heiko Seeberger
Thanks

Introduction to ScalaZ

  • 1.
    Introduction to ScalaZ PrabhatKashyap Trainee Software Consultant Knoldus Software LLP
  • 2.
    What is Scalaz ●It is just another library for Scala.
  • 3.
    What is Scalaz ●It is just another library for Scala. ● Scalaz is purely functional library.
  • 4.
    What is Scalaz ●It is just another library for Scala. ● Scalaz is purely functional library. ● It provides new functions.
  • 5.
    What is Scalaz ●It is just another library for Scala. ● Scalaz is purely functional library. ● It provides new functions. ● It’s an open source project (https://github.com/scalaz/scalaz)
  • 6.
  • 7.
    Whats wrong withthis code: val internInProject = Map( "Prabhat" -> "ScalaGeek", "Kunal" -> "FitFyles", "Himani" -> "FitFyles" ) def isInternFromProject(project: String, intern: String): Boolean = (internInProject get intern) == project
  • 8.
    Whats wrong withthis code: val internInProject = Map( "Prabhat" -> "ScalaGeek", "Kunal" -> "FitFyles", "Himani" -> "FitFyles" ) def isInternFromProject(project: String, intern: String): Boolean = (internInProject get intern) == project == is not typesafe here IsInternFromProject will always return false
  • 9.
    Let’s try onemore val intern1 = Map( "Prabhat" -> Map("scalageek" -> 10, "FitFyles" -> 1), "Aarwee" -> Map("FitFyles" -> 6, "ScalaGeek" -> 3), "Deepti" -> Map("FitFyles" -> 11) ) val intern2 = Map( "Prabhat" -> Map("scalageek" -> 3) ) Now you can write a complex code with map functions
  • 10.
    Let’s try onemore val intern1 = Map( "Prabhat" -> Map("scalageek" -> 10, "FitFyles" -> 1), "Aarwee" -> Map("FitFyles" -> 6, "ScalaGeek" -> 3), "Deepti" -> Map("FitFyles" -> 11) ) val intern2 = Map( "Prabhat" -> Map("scalageek" -> 3) ) Or you can use |+| val combinedResult = (intern1 |+| intern2)
  • 11.
    Let’s try onemore val intern1 = Map( "Prabhat" -> Map("scalageek" -> 10, "FitFyles" -> 1), "Aarwee" -> Map("FitFyles" -> 6, "ScalaGeek" -> 3), "Deepti" -> Map("FitFyles" -> 11) ) val intern2 = Map( "Prabhat" -> Map("scalageek" -> 3) ) Or you can use |+| val combinedResult = (intern1 |+| intern2) Map( "Prabhat" -> Map("scalageek" -> 13, "FitFyles" -> 1), "Aarwee" -> Map("FitFyles" -> 6, "ScalaGeek" -> 3), "Deepti" -> Map("FitFyles" -> 11)) And Combined Result will be
  • 12.
    Why ScalaZ ● Scalazis a library for doing pure Functional Programming in Scala.
  • 13.
    Why ScalaZ ● Scalazis a library for doing pure Functional Programming in Scala. ● Scalaz does not encourage subtyping—instead it espouses typeclass-based ad hoc polymorphism using higher order functions.
  • 14.
    Why ScalaZ ● Scalazis a library for doing pure Functional Programming in Scala. ● Scalaz does not encourage subtyping—instead it espouses typeclass-based ad hoc polymorphism using higher order functions. ● Scalaz comes with a lot of built in typeclasses and encourages you to build your own.
  • 15.
    Today we onlybe looking at Scalaz Typeclasses
  • 16.
  • 17.
  • 18.
    ScalaZ Typeclasses ● Equal[A]typeclass ● Order ● Enum
  • 19.
    ScalaZ Typeclasses ● Equal[A]typeclass ● Order ● Enum
  • 20.
    ScalaZ Typeclasses ● Equal[A]typeclass ● Order ● Enum ● Options
  • 21.
    ScalaZ Typeclasses ● Equal[A]typeclass ● Order ● Enum ● Options
  • 22.
    ScalaZ Typeclasses ● Equal[A]typeclass ● Order ● Enum ● Options ● Validation
  • 23.
    ScalaZ Typeclasses ● Equal[A]typeclass ● Order ● Enum ● Options ● Validation
  • 24.
  • 25.
    References ● Wikipedia ● http://eed3si9n.com/ ●Youtube – Scalaz Presentation - Nick Partridge – Introduction to Scalaz - Heiko Seeberger
  • 26.