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 | |
Welcome to Scala version 2.11.7 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_31). | |
Type in expressions to have them evaluated. | |
Type :help for more information. | |
scala> :paste | |
// Entering paste mode (ctrl-D to finish) | |
trait Monad[F[_]] { | |
def pure[A](a: A): F[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
package foo | |
import shapeless._ | |
import shapeless.poly._ | |
trait Extract[F[_]] { | |
def extract[A](fa: F[A]): A | |
def extractAll[K <: HList](k: K)(implicit m: ops.hlist.Mapper[Extract.extract.type, K]) = | |
Extract.extractAll[F, K](k)(this, m) | |
} |
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 mf | |
import cats._ | |
import cats.laws._ | |
trait MonadFix[F[_]] extends Monad[F] { | |
def mfix[A](f: Eval[A] => F[A]): F[A] | |
} | |
object MonadFix { |
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
[error] /Users/mpilquist/Development/projects/simulacrum/core/src/main/scala/simulacrum/typeclass.scala:58: type mismatch; | |
[error] found : String | |
[error] required: Int | |
[error] def freshName(prefix: String) = c.freshName(prefix) | |
[error] ^ | |
[error] /Users/mpilquist/Development/projects/simulacrum/core/src/main/scala/simulacrum/typeclass.scala:288: not found: value typeNames | |
[error] tparamtparams.find { _.name == typeNames.WILDCARD } match { | |
[error] ^ | |
[error] /Users/mpilquist/Development/projects/simulacrum/core/src/main/scala/simulacrum/typeclass.scala:295: not found: value typeNames | |
[error] case Ident(typeNames.WILDCARD) => super.transform(Ident(liftedTypeArgName)) |
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._ | |
import UnaryTCConstraint._ | |
object inv { | |
trait Zip[F[_]] { | |
def pure[A](a: A): F[A] | |
def zip[A, B](fa: F[A], fb: F[B]): F[(A, B)] | |
} |
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
target |
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> import scala.reflect.runtime.universe._ | |
import scala.reflect.runtime.universe._ | |
scala> showCode(reify { | |
| for{ | |
| x <- 1 to 5 | |
| _ = print("hi") | |
| } print(x) | |
| }.tree) | |
res1: String = |
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._ | |
package object ex { | |
implicit class TypeClassHListOps[L <: HList](val self: L) extends AnyVal { | |
def summon[TC[_]](implicit op: HListTypeClassSummoner[TC, L]) = op.instance | |
} | |
trait HListTypeClassSummoner[TC[_], L <: HList] { | |
type Out <: HList |
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
def local[A](implicits: Any*)(f: => A): A = macro localMacro[A] | |
def localMacro[A](c: Context)(implicits: c.Expr[Any]*)(f: c.Expr[A]): c.Expr[A] = { | |
import c.universe._ | |
val implicitVals = implicits.map { imp => | |
val name = TermName(c.freshName()) | |
q"implicit val $name = $imp" | |
} | |
c.Expr[A](q"{ ..$implicitVals; $f }") | |
} |