Skip to content

Instantly share code, notes, and snippets.

/*
* 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
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)
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]
@mpilquist
mpilquist / test.scala
Last active December 22, 2015 08:59 — forked from milessabin/gist:6448380
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])
}
}
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)