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
scala> class Foo | |
defined class Foo | |
scala> val foo = new Foo | |
foo: Foo = Foo@6df280a7 | |
scala> foo: foo.type | |
res0: foo.type = Foo@6df280a7 | |
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._ | |
import shapeless.ops.hlist.Tupler | |
trait Evaluator[L <: HList] { | |
type Out <: HList | |
def apply(value:String, l:L):Option[Out] | |
} | |
object Evaluator { |
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
// An ADT+shapeless as a drop-in replacement for a standard Scala Enumeration. | |
// | |
// First the unsafe standard Scala Enumeration ... | |
// | |
object ScalaEnumDemo extends App { | |
// Example from scala.Enumeration scaladoc. Terse ... | |
object WeekDay extends Enumeration { | |
type WeekDay = Value | |
val Mon, Tue, Wed, Thu, Fri, Sat, Sun = Value | |
} |
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._ | |
object Values { | |
implicit def conv[T](self: this.type)(implicit v: MkValues[T]): Set[T] = Values[T] | |
def apply[T](implicit v: MkValues[T]): Set[T] = v.values.toSet | |
trait MkValues[T] { | |
def values: List[T] | |
} |
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._ | |
/** | |
* Functional update of common fields of an *open* family of case classes | |
* via a case-class-like copy through the common super type ... | |
* | |
* This is a follow up to my earlier post showin how to do functional | |
* update for a sealed family of case classes, | |
* | |
* https://gist.github.com/milessabin/a212d946aef33811fee1 |
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._ | |
object CaseClassMergeDemo extends App { | |
import mergeSyntax._ | |
case class Foo(i: Int, s: String, b: Boolean) | |
case class Bar(b: Boolean, s: String) | |
val foo = Foo(23, "foo", true) | |
val bar = Bar(false, "bar") |
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._ | |
/** | |
* Functional update of common fields of a sealed family of case classes | |
* via a case-class-like copy through the common super type ... | |
*/ | |
object BaseCopyDemo extends App { | |
import copySyntax._ | |
// Sealed family of case classes ... |
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
trait Pet { | |
type This <: Pet | |
def name: String | |
def renamed(newName: String): This | |
} | |
case class Fish(name: String, age: Int) extends Pet { | |
type This = Fish | |
def renamed(newName: String): This = copy(name = newName) | |
} |
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
package shapeless.examples | |
import shapeless._ | |
import poly._ | |
import labelled._ | |
sealed trait Message | |
case class Ping(id: Long, sender: String) extends Message | |
case class Pong(id: Long, receiver: String) extends Message |
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
package fommil.polys | |
import shapeless._ | |
sealed trait Trait | |
case class Foo() extends Trait | |
case class Bar() extends Trait | |
trait Thing[T] { def thingy: String } |