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 ext extends StaticAnnotation { | |
def macroTransform(annottees: Any*) = macro extension.impl | |
} | |
object extension { | |
def impl(c: Context)(annottees: c.Expr[Any]*): c.Expr[Any] = { | |
import c.universe._ | |
annottees.map{ _.tree }.head match { | |
case q"def $name[..$tp](...$params): $ret = $b" => | |
val Seq(Seq(thiz, rest @ _*), rest2 @ _*) = params |
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 Foldable[F[_]] { | |
def foldLeft[A, B](fa: F[A], b: B)(f: (B, A) => B): B | |
} | |
object Foldable extends Foldable0 { | |
def apply[F[_]](implicit F: Lazy[Foldable[F]]): Foldable[F] = F.value | |
implicit val idFoldable: Foldable[Id] = |
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.tools.nsc._, reporters._; val reporter = new StoreReporter; val settings = new Settings(); settings.processArgumentString("-usejavacp -Ystop-after:refchecks"); val global = new Global(settings, reporter) | |
import scala.tools.nsc._ | |
import reporters._ | |
reporter: scala.tools.nsc.reporters.StoreReporter = scala.tools.nsc.reporters.StoreReporter@5e18a6a7 | |
settings: scala.tools.nsc.Settings = | |
Settings { | |
-d = . | |
-Ystop-after = List(refchecks) | |
-usejavacp = true | |
-encoding = UTF-8 |
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.labelled._ | |
import shapeless.ops.record._ | |
import scala.annotation.implicitNotFound | |
@implicitNotFound("Cannot prove that ${A} has an 'id: Int' field.") | |
trait HasId[A] { | |
def apply(a: A): Int | |
} |
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 T { | |
val t = "T" | |
} | |
class U | |
class V | |
object T { | |
implicit def UToT[UU <% U](u: UU) = new 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
object Union { | |
type ¬[A] = A => Nothing | |
type ¬¬[A] = ¬[¬[A]] | |
type ∨[T, U] = ¬[¬[T] with ¬[U]] | |
type |∨|[T, U] = { type λ[X] = ¬¬[X] <:< (T ∨ U) } | |
def size[@specialized(Int) T : (Int |∨| String)#λ](t : T) = t match { | |
case i : Int => i | |
case s : String => s.length | |
} |
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 demo | |
class SafeUnsafe { | |
def unsafe[T](x: =>T):Option[T]= try { | |
Option(x) | |
} catch { | |
case _ => None | |
} |
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 test; | |
import java.lang.{reflect => jreflect} | |
import scala.reflect.mirror._ | |
/** | |
* Scala counterpart of java.lang.reflect.InvocationHandler | |
*/ | |
trait InvocationHandler { | |
def invoke(proxy: AnyRef, method: Symbol, args: Array[AnyRef]): AnyRef |
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 await | |
import java.util.concurrent.Callable | |
import java.util.concurrent.Executors | |
object BlockingDemo extends App { | |
val execSvc = Executors.newSingleThreadExecutor() | |
val worker = new MeaningOfLife() |
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 Poc2 { | |
trait TARInt | |
trait Basket[A,B] { | |
def iAmABasket = {} | |
} | |
trait BasketFactory[A,B] { | |
def create(v: A): Basket[A,B] |
OlderNewer