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.instances.option._ | |
import cats.{Id, Monad} | |
import scala.language.higherKinds | |
/** | |
* This class solves the problem where you need to perform essentially the same operation, via implicit classes, upon both raw values (Int, String, etc.) and | |
* also upon their optional equivalents (Option[Int], Option[String], etc.). Normally, for each operation, you would need to write two implicit classes: | |
* {{{ | |
* implicit class StringImplicits(s: 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.annotation.StaticAnnotation | |
import scala.language.experimental.macros | |
import scala.reflect.macros.whitebox | |
class JsonReads extends StaticAnnotation { | |
def macroTransform(annottees: Any*): Any = macro JsonConversion.readsImpl | |
} | |
class JsonWrites extends StaticAnnotation { | |
def macroTransform(annottees: Any*): Any = macro JsonConversion.writesImpl |
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.annotation.StaticAnnotation | |
import scala.language.experimental.macros | |
import scala.reflect.macros.whitebox | |
/** | |
* Example: | |
* {{{ | |
* @GeneratePartialModel(fieldsToRestrict = "id") | |
* case class User(id: Int, name: String, email: Option[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 java.time.{Clock, Instant, ZoneId} | |
class NanoClock(private val clock: Clock) extends Clock { | |
def this() { this(Clock.systemUTC) } | |
private val initialInstant = clock.instant | |
private val initialNanos = System.nanoTime | |
override def getZone: ZoneId = clock.getZone |
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
@tailrec def partition[A, B](in: List[Either[A, B]], out: (List[A], List[B]) = (Nil, Nil)): (List[A], List[B]) = in match { | |
case Nil => out | |
case Left(a) :: tail => partition(tail, (a :: out._1, out._2)) | |
case Right(b) :: tail => partition(tail, (out._1, b :: out._2)) | |
} |
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 test | |
import scala.reflect.runtime.universe._ | |
object ReflectionHelpers extends ReflectionHelpers | |
trait ReflectionHelpers { | |
protected val classLoaderMirror = runtimeMirror(getClass.getClassLoader) |