Skip to content

Instantly share code, notes, and snippets.

View blast-hardcheese's full-sized avatar

Devon Stewart blast-hardcheese

View GitHub Profile
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))
class Hey @Inject() (val app: Application) {
app.configuration // Guaranteed to work, since we can never get here unless we have enough contructor parameters
}
{% 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
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)
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
...
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] }
...
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
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 {
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
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)