Nick Partridge
@nkpart




                 Scalaz
                 (scahla-zed)
Scalaz
New datatypes:
• Validation
• NonEmptyList
• Dlist
• More
Scalaz

Extensions to standard classes
• OptionW
• ListW
• etc.
Scalaz

Implementation of every single general
function you need.
• Ad-hoc Polymorphism
• Traits + Implicit Parameters + Implicit
   Conversions.
Ad-hoc Polymorphism

• What is polymorphism?
  def head[T](xs: List[T]): T = ...


  Any T will be fine.
Ad-hoc Polymorphism

• What makes it ad-hoc? Restrictions.
  def show[T](t: T): String =...



  Not all T’s can be Strings.
Ad-hoc Polymorphism


• Typically achieved through interitance.
  def show[T <: Show[T]](t: T) = ...
Ad-hoc Polymorphism

• In scalaz, we use Traits
 • But no Inheritance.
• Make it nice:
 • Implicit parameters and implicit
    conversions.
Live Demo

   def sum(xs: List[Int]) : Int
               to
def sum[M[_], A](xs: M[A])(...): A
Typeclasses in Scalaz

• Monoid - append, zero
• FoldLeft
• Functor - map
• Monad - bind, return
• Many more...
Making it Nice

       Questions?


 Live code. Pimping time.
Making it Nice
The Pimps of Scalaz
  • Identity -> A
  • MA -> M[A]
  • MAB -> M[A, B]
  • More as necessary -> One per ‘kind’
Making it Nice
object Scalaz extends ... { ... }
   • Includes all Implicit conversions
    • Pimps and Extensions
   • General constructors:
    • some(x), none
Making it Nice
Usage:
          import scalaz._
          import Scalaz._
          ...
          List(1,2) |+| List(3,4)
New Datatypes


• NonEmptyList
• Validation
NonEmptyList
• Guaranteed Not Empty.
• Construct via Identity:
  • value.wrapNel
• General constructors:
 • nel(head, tail)
 • nel1(head, tail...) <- varargs
Validation
• Disjunction
• Right-biased Either
• Failures on the left.
• Constructors:
 • value.fail, value.success
 • success(value), failure(value)
Scalaz - Console

Live demo
• NonEmptyList
• Validation
• OptionW - ~
Learn More.
• scalaz/examples
• `Typeclassopedia`
• Haskell (particularly the wiki)
• #functionaljava
• Mailing list: http://code.google.com/p/scalaz
• Source: http://github.com/scalaz/scalaz

Deriving Scalaz