GitHub

MaxwellBo/A-tour-of-Scala

MaxwellBo/scratches

Ammonite Snippets

Setting up Ammonite for Cats

interp.configureCompiler(_.settings.YpartialUnification.value = true) // very useful!

import $ivy.`org.typelevel::cats-core:1.0.1`, cats.implicits._
trait StateFunctions {
  def constantState[S, A](a: A, s: => S): State[S, A] =
    State((_: S) => (s, a))

  def state[S, A](a: A): State[S, A] =
    State((_ : S, a))

  def init[S]: State[S, S] = State(s => (s, s))

  def get[S]: State[S, S] = init

  def gets[S, T](f: S => T): State[S, T] = State(s => (s, f(s)))

  def put[S](s: S): State[S, Unit] = State(_ => (s, ()))

  def modify[S](f: S => S): State[S, Unit] = State(s => {
    val r = f(s);
    (r, ())
  })
}
[info] #total compile time           : 1 spans, ()584686.695ms
[info]   parser                      : 1 spans, ()1366.783ms (0.2%)
[info]   kind-projector              : 1 spans, ()471.297ms (0.1%)
[info]   namer                       : 1 spans, ()1105.115ms (0.2%)
[info]   packageobjects              : 1 spans, ()127.169ms (0.0%)
[info]   typer                       : 1 spans, ()567961.388ms (97.1%)
[info]   patmat                      : 1 spans, ()1840.127ms (0.3%)
[info]   superaccessors              : 1 spans, ()195.637ms (0.0%)
[info]   extmethods                  : 1 spans, ()68.266ms (0.0%)
[info]   pickler                     : 1 spans, ()217.933ms (0.0%)
[info]   xsbt-api                    : 1 spans, ()1113.686ms (0.2%)
[info]   xsbt-dependency             : 1 spans, ()486.431ms (0.1%)
[info]   refchecks                   : 1 spans, ()685.896ms (0.1%)
[info]   uncurry                     : 1 spans, ()1141.685ms (0.2%)
[info]   fields                      : 1 spans, ()254.909ms (0.0%)
[info]   tailcalls                   : 1 spans, ()177.163ms (0.0%)
[info]   specialize                  : 1 spans, ()810.716ms (0.1%)
[info]   explicitouter               : 1 spans, ()208.45ms (0.0%)
[info]   erasure                     : 1 spans, ()2094.326ms (0.4%)
[info]   posterasure                 : 1 spans, ()132.033ms (0.0%)
[info]   lambdalift                  : 1 spans, ()400.361ms (0.1%)
[info]   constructors                : 1 spans, ()182.124ms (0.0%)
[info]   flatten                     : 1 spans, ()96.757ms (0.0%)
[info]   mixin                       : 1 spans, ()188.837ms (0.0%)
[info]   cleanup                     : 1 spans, ()80.02ms (0.0%)
[info]   delambdafy                  : 1 spans, ()335.677ms (0.1%)
[info]   jvm                         : 1 spans, ()2773.593ms (0.5%)
[info]   xsbt-analyzer               : 1 spans, ()36.532ms (0.0%

Roll-your-own Scala

Freer doesn't come for free

Typelevel.scala | Treelog

Scala is 12 languages that happen to share the same compiler, unfortunately only some of them are good languages and its too hard to limit the compiler to which subset you actually want