Skip to content

Instantly share code, notes, and snippets.

@tusharmath
Last active January 9, 2018 03:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tusharmath/eb66fdbb0af39b2c37ccd8c66154a4e4 to your computer and use it in GitHub Desktop.
Save tusharmath/eb66fdbb0af39b2c37ccd8c66154a4e4 to your computer and use it in GitHub Desktop.
Notes

Scala Cheatsheet

Type Constructors

case classes that help use create new type of objects. For instance List is a type constructory.

Higher Kinded Types

Generic types that take parameters such as —

trait Foo[T[_]] {
  def bar(x: T[Int]): Unit
}

Sealed Traits

When we define an algebraic data type using sealed traits we allow the compiler to perform exhaustiveness checking. In simpler words, this means the compiler will shout at us if we miss out a case in our structural recursion.

scala> Option(1) match {
     |   case None => "Yeah"
     | }
<console>:8: warning: match may not be exhaustive.
It would fail on the following input: Some(_)
              Option(1) match {
                    ^

A sealed trait can only be extended within the file in which it defined. more

Final Trait

final class/trait cannot be extended anywhere. more

Universally Quantified Type

A type constructor is a universally quantified type, which can be used to construct types.

sealed trait List[A]
case class Nil[A]() extends List[A]
case class Cons[A](head: A, tail: List[A]) extends List[A]

List is type constructor, which defines a family of List-like types, including List[Boolean] (the type of lists of booleans). List is said to be universally quantified over its type variable A.

TrieMap

ParTrieMap

Special functions

 - update() used as the default setter method  - apply() used as the default getter method

  • this() used as a constructor

TraitBuilder

TraitCombiner

ScalaZ notes

more

Implicits

Algebraic Data Type

Scala Enum

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment