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
// full implementation at https://github.com/ghik/selftyped | |
trait Base extends SelfTyped { | |
def same[T: Self]: T | |
def twice[T: Self]: T | |
} | |
trait SimpleSame extends Base { | |
// we can always safely return 'this' where self-type is expected |
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
class Base { | |
def work() { | |
// do some work | |
} | |
} | |
trait Logging extends Base { | |
override def work() { | |
log("Doing work") | |
super.work() |
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.implicitConversions | |
final class Opt[+A] private(private val value: Any) extends AnyVal { | |
def isEmpty = value == null | |
def isDefined: Boolean = !isEmpty | |
def get: A = value.asInstanceOf[A] | |
} |
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 RegexInterpolations._ | |
val str = "My hovercraft is full of eels" | |
str match { | |
case r"""My (\w+)$vehicle is full of (\w+)$stuff""" => | |
println(s"It is $stuff that my $vehicle is full of.") | |
} |
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 hoconspring.HoconType | |
import scala.language.experimental.macros | |
import scala.reflect.macros.blackbox | |
object BigMac { | |
def materializeHoconType[T]: HoconType[T] = macro materializeHoconType_impl[T] | |
def materializeHoconType_impl[T: c.WeakTypeTag](c: blackbox.Context): c.Expr[HoconType[T]] = { | |
import c.universe._ |
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
scala> type AbsolutelyNothing = Nothing { type MoreNothing = Nothing } | |
defined type alias AbsolutelyNothing | |
scala> typeOf[Nothing] <:< typeOf[AbsolutelyNothing] | |
res0: Boolean = true | |
scala> typeOf[AbsolutelyNothing] <:< typeOf[Nothing] | |
res1: Boolean = true | |
scala> typeOf[Nothing] =:= typeOf[AbsolutelyNothing] |
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 com.avsystem.commons | |
package misc | |
import org.scalatest.FunSuite | |
/** | |
* Author: ghik | |
* Created: 23/11/15. | |
*/ | |
class SamTest extends FunSuite { |
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 org.scalatest.FunSuite | |
import scala.language.higherKinds | |
/** | |
* Author: ghik | |
* Created: 26/11/15. | |
*/ | |
class DelegationTest extends FunSuite { | |
trait Destination[T] { |
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 Zapieczętowany { | |
def accept[T](forPrzypadek: JFunction[Przypadek,T], forNieSądzę: JFunction[NieSądzę,T]): T = this match { | |
case p: Przypadek => forPrzypadek(p) | |
case ns: NieSądzę => forNieSądzę(ns) | |
} | |
} | |
case class Przypadek() extends Zapieczętowany | |
case class NieSądzę() extends Zapieczętowany |
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.higherKinds | |
sealed abstract class Stuff[+A] | |
case class Suspend[A](a: () => mutable.Set[A]) | |
extends Stuff[A] | |
def extract[A](source: Stuff[A]): Suspend[A] = | |
source match { | |
case ref @ Suspend(_) => ref |
OlderNewer