This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Age private (val v: Short) extends AnyVal { | |
def isInfant = v < 2 | |
def isToddler = v >= 2 && v <= 4 | |
def isSenior = v >= 50 | |
} | |
object Age { | |
def apply(v: Short): Age = { | |
require(v >= 0 && v < 200, "Must be between 0 and 200") | |
new Age(v) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import shapeless._ | |
trait F[A] { | |
def xmap[B](f: A => B, g: B => A): F[B] | |
def as[B] = new AsAux[B] | |
class AsAux[B] { | |
def apply[C](implicit gen: Generic.Aux[B, C], ev: A =:= C): F[B] = | |
xmap(a => gen.from(ev(a)), b => gen.to(b).asInstanceOf[A]) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sealed trait Interact[A] | |
case class Ask(prompt: String) | |
extends Interact[String] | |
case class Tell(msg: String) | |
extends Interact[Unit] | |
trait Monad[M[_]] { | |
def pure[A](a: A): M[A] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object CaseClassToMapStringOfString { | |
import shapeless._ | |
import shapeless.labelled._ | |
import syntax.singleton._ | |
import record._ | |
import ops.record._ | |
import syntax.singleton._ | |
case class Color(value: String) | |
case class ChartOptions(stringOpt: String, intOpt: Int, colorOpt: Color) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Copyright 2020 Daniel Spiewak | |
* | |
* Licensed under the Apache License, Version 2.0 (the "License"); | |
* you may not use this file except in compliance with the License. | |
* You may obtain a copy of the License at | |
* | |
* http://www.apache.org/licenses/LICENSE-2.0 | |
* | |
* Unless required by applicable law or agreed to in writing, software |