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 cats._ | |
import cats.effect.IO | |
import cats.implicits._ | |
case class UserId(value: String) extends AnyVal | |
case class User(id: UserId, name: String, age: Int) | |
trait DbApi[F[_]] { | |
def load(id: UserId): F[Option[User]] | |
def save(user: User): F[Unit] |
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.openjdk.jmh.annotations._ | |
final class NoStackTraceIndexOutOfBoundsException extends IndexOutOfBoundsException { | |
override def fillInStackTrace(): Throwable = this | |
} | |
final class NoStackTraceArraySeq[+T](values: Array[T]) { | |
val size: Int = values.length | |
def apply(idx: Int): 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
import java.lang.reflect.{GenericArrayType, Modifier, ParameterizedType, Type, TypeVariable, WildcardType} | |
import scala.reflect.{ClassTag, classTag} | |
object StaticForwarderGenerator { | |
implicit class arrayOps[A](private val array: Array[A]) extends AnyVal { | |
def mkStringOrEmpty(start: String, sep: String, end: String): String = | |
if (array.isEmpty) "" else array.mkString(start, sep, end) | |
} | |
def generateFor[T: ClassTag]: 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
import scala.language.higherKinds | |
sealed abstract class Stuff[F[_], +A] | |
case class Suspend[F[_], A](a: () => F[A]) | |
extends Stuff[F, A] | |
def extract[F[_], A](source: Stuff[F, A]): Suspend[F, A] = | |
source match { | |
case ref @ Suspend(_) => ref.asInstanceOf[Suspend[F,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 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 |
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 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
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
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
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._ |
NewerOlder