This file contains hidden or 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
| def cast[T](v: Any): Unit = v.asInstanceOf[T] | |
| def cast1[T](v: Any): T = v.asInstanceOf[T] | |
| val v = BigInt(3) | |
| cast[Double](v) // no exception, there should be one | |
| cast1[Double](v) // exception, but from repl code after cast1 itself |
This file contains hidden or 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 scala.language.experimental.macros | |
| import scala.reflect.macros.whitebox | |
| import scala.annotation.meta.getter | |
| object FirstAnnotation { | |
| def applyImpl[T: c.WeakTypeTag, Ann: c.WeakTypeTag](c: whitebox.Context): c.Tree = { | |
| import c.universe._ | |
| val tpe = weakTypeOf[T] | |
| val annTpe = weakTypeOf[Ann] |
This file contains hidden or 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 gen | |
| import shapeless._, record._, labelled._ | |
| trait TC[T] | |
| object TC { | |
| def apply[T](implicit tc: TC[T]): TC[T] = tc | |
| implicit val booleanTC: TC[Boolean] = new TC[Boolean] {} |
This file contains hidden or 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 java.util.Locale | |
| import javax.servlet.http.{Cookie, HttpServletResponse} | |
| class Dummy extends xsbti.AppMain { | |
| def run(config: xsbti.AppConfiguration) = | |
| try { | |
| // Creating a dummy HttpServletResponse | |
| // - succeeds from sbt run or sbt console | |
| // - fails through launchconfig using the `dummy` script below (NoClassDefFound exception) | |
| val r = new HttpServletResponse { |
This file contains hidden or 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 tag.@@ | |
| import record._ | |
| trait CustomTag | |
| case class Dummy(i: Int @@ CustomTag) | |
| case class DummyTagged(b: Boolean, i: Int @@ CustomTag) | |
| object Test extends App { | |
| val gen = Generic[Dummy] |
This file contains hidden or 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 | |
| package examples | |
| import scalaz.@@ | |
| import labelled._ | |
| import record._ | |
| trait TC[T] { | |
| def apply(): String | |
| } |
This file contains hidden or 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 Base0 | |
| case class Foo0() extends Base0 | |
| case class Bar0() extends Base0 | |
| sealed trait Base1 | |
| case object Foo1 extends Base1 | |
| case object Bar1 extends Base1 | |
| object Base { | |
| Generic[Foo0] |
This file contains hidden or 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
| case class Foo0() | |
| case class Foo1(i: Int) | |
| object Lgen2 { | |
| import shapeless._ | |
| import language.experimental.macros | |
| // Works with this one, but hard to do anything with it then... | |
| implicit def lgen[T]: shapeless.LabelledGeneric[T] = macro shapeless.GenericMacros.materializeLabelled[T, Nothing] |
This file contains hidden or 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
| case class Foo0() | |
| case class Foo1(i: Int) | |
| object Lgen { | |
| import shapeless._ | |
| LabelledGeneric[Foo0] | |
| LabelledGeneric[Foo1] | |
| } |
This file contains hidden or 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 TC[T] { | |
| def apply(t: T): String | |
| } | |
| object TC { | |
| implicit def hnilTC: TC[HNil] = | |
| new TC[HNil] { | |
| def apply(l: HNil) = "HNil" | |
| } |