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 se.hardchee.Pickr | |
import scala.language.higherKinds | |
import scala.language.implicitConversions | |
import scalaz.{ Coproduct, Free, Inject, ~>, \/-, -\/ } | |
package object algebras { | |
implicit def liftFCInj[A, P[_], F[_]](x: P[A])(implicit I: Inject[P, F]): Free.FreeC[F, A] = { | |
Free.liftFC(I.inj(x)) |
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 Hey @Inject() (val app: Application) { | |
app.configuration // Guaranteed to work, since we can never get here unless we have enough contructor parameters | |
} |
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
{% from 'java/map.jinja' import java with context %} | |
{% import_yaml 'gocd/defaults.yaml' as default_settings %} | |
{% set java_env = salt['pillar.get']('java:env', default='jre7') %} | |
{% do gocd.update({ | |
'server': (gocd.get('server')|default({})).update({ | |
'JAVA_HOME': java[java_env].home | |
}), | |
'agent': (gocd.get('agent')|default({})).update({ | |
'JAVA_HOME': java[java_env].home |
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> implicit class IInt(val value: Int) | |
defined class IInt | |
scala> def something(implicit int: IInt) = s"Deep down, got ${int.value}" | |
something: (implicit int: IInt)String | |
scala> def somethingElse(implicit int: IInt) = something | |
somethingElse: (implicit int: IInt)String | |
scala> somethingElse(5) |
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> import shapeless.tag | |
import shapeless.tag | |
scala> trait FirstName | |
defined trait FirstName | |
scala> val FirstName = tag[FirstName] | |
FirstName: shapeless.tag.Tagger[FirstName] = shapeless.tag$Tagger@779a0926 | |
scala> trait LastName |
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
... | |
type FirstName = (String @@ FirstName.Internal) | |
object FirstName { trait Internal; def apply(value: String): FirstName = value.asInstanceOf[FirstName] } | |
type LastName = (String @@ LastName.Internal) | |
object LastName { trait Internal; def apply(value: String): LastName = value.asInstanceOf[LastName] } | |
type Email = (String @@ Email.Internal) | |
object Email { trait Internal; def apply(value: String): Email = value.asInstanceOf[Email] } | |
... |
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 shapeless._ | |
case class Location(lat: Double, lon: Double) | |
case class User(id: Long, username: String, location: Location) | |
case class Car(id: Long, location: Location) | |
object ImplicitLenses extends App { | |
implicit val userLocationLens: Lens[User, Location] = { | |
val ret = lens[User].location | |
ret |
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 shapeless._ | |
import shapeless.labelled.KeyTag | |
import shapeless.record._ | |
import shapeless.ops.hlist.ToList | |
import shapeless.ops.record.{ Keys, Values } | |
import shapeless.syntax.singleton._ | |
import utils.ExtendedPostgresDriver.simple._ | |
object slickless { |
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 shapeless._ | |
sealed trait Animal | |
case class Point(x: Double, y: Double) | |
case class Color(r: Byte, g: Byte, b: Byte) | |
case class Turtle(position: Point, heading: Double, color: Color) extends Animal | |
case class Cat(position: Point, color: Color) extends Animal | |
implicit val turtlePosition = lens[Turtle].position | |
implicit val catPosition = lens[Cat].position |
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
def split[A, B](f: A => A => C)(x: A): C = f(x)(x) | |
def swap[A, B, C](f: A => B => C): B => A => C = (b: B) => (a: A) => f(a)(b) | |
def filter[A](as: List[A])(f: A => Boolean): List[A] = foldRight2(as, List.empty[A])(uncurried[A, List[A], List[A]](split(f andThen (if(_) (Cons.apply[A] _).curried else swap(const[List[A], A] _))) _)) | |
def filterAnnotated[A](as: List[A])(f: A => Boolean): List[A] = { | |
val prepend: A => List[A] => List[A] = (Cons.apply[A] _).curried | |
val ignore: A => List[A] => List[A] = swap(const[List[A], A] _) | |
val getApply: A => A => List[A] => List[A] = f andThen (if(_) prepend else ignore) |