Skip to content

Instantly share code, notes, and snippets.

View EECOLOR's full-sized avatar

EECOLOR EECOLOR

  • Kaliber
  • Utrecht, Netherlands
View GitHub Profile
@EECOLOR
EECOLOR / hList-validation
Last active August 29, 2015 13:56
HList as a basis for validation and conversion. Using fold on nested HList. Applying method on elements in HList tree
import shapeless._
import shapeless.ops.hlist._
import scala.util.Try
object validation {
trait Violation {
def message: String
}
abstract class SimpleViolation(val message: String) extends Violation
@EECOLOR
EECOLOR / freemonads.scala
Last active August 29, 2015 14:02 — forked from runarorama/gist:a8fab38e473fafa0921d
Free monads
sealed trait Interact[A]
case class Ask(prompt: String)
extends Interact[String]
case class Tell(msg: String)
extends Interact[Unit]
trait Monad[M[_]] {
def pure[A](a: A): M[A]
@EECOLOR
EECOLOR / TypeList.scala
Last active August 29, 2015 14:03
Collecting types in a type list (an HList without actual values). Adding and Finding types in that list on a a type level
package test2
import scala.language.higherKinds
trait T1[A]
trait T2[A]
trait T3[A]
trait TypeList
trait Nil extends TypeList
@EECOLOR
EECOLOR / project_FakeHttpServletRequest.scala
Last active August 29, 2015 14:03
Experiment running railo from sbt
import javax.servlet.http.HttpServletRequest
class FakeHttpServletRequest extends HttpServletRequest {
// Members declared in javax.servlet.http.HttpServletRequest
def authenticate(x$1: javax.servlet.http.HttpServletResponse): Boolean = ???
def getAuthType(): String = ???
def getContextPath(): String = "/"
def getCookies(): Array[javax.servlet.http.Cookie] = Array.empty
def getDateHeader(x$1: String): Long = ???
def getHeader(x$1: String): String = ???
@EECOLOR
EECOLOR / _1_TypedActor.scala
Last active August 29, 2015 14:06
An alternative version of typed actors. Actors can only receive messages of a certain type, the type parameter determines the return type.
package experiment
import scala.concurrent.ExecutionContext
import scala.concurrent.Future
import scala.language.higherKinds
import scala.language.implicitConversions
import scala.reflect.ClassTag
import akka.actor.Actor
import akka.actor.ActorRef
@EECOLOR
EECOLOR / cyclic.sbt
Created September 17, 2014 19:38
Sbt cyclic project dependencies. Helps in tying projects together if they depend on eachother.
internalDependencyClasspath in Compile in `play-cms-testing` +=
interProjectDependency(`play-cms`, Compile).value
internalDependencyClasspath in Test in `play-cms` +=
interProjectDependency(`play-cms-testing`, Compile).value
def interProjectDependency(project:Project, configuration:Configuration) = Def.task {
Attributed.blank(
(classDirectory in configuration in project)
.map(identity) // convert the setting into a task
@EECOLOR
EECOLOR / ProgramTypeHelpers.scala
Created October 5, 2014 11:31
Clean construction of coproducts
trait Co[F[_], G[_]] {
case class Product[A](value: Either[F[A], G[A]])
}
trait ProgramType[F[_]]
object ProgramType {
def apply[T](implicit to: ToParameterized[T]): ProgramType[to.Out] = ???
}
trait ToParameterized[T] {
@EECOLOR
EECOLOR / como.scala
Last active August 29, 2015 14:15 — forked from paulp/como.scala
package p {
object Test {
import construction.Monadic
import execution.Bimonad
def main(args: Array[String]): Unit = {
val expression = Monadic[List](10) flatMap (1 to _ toList) coflatMap (_.sum)
@EECOLOR
EECOLOR / Party.scala
Created March 12, 2015 19:52
If characters were chocolate and parsers were girls, what would happen? (this code has not been tested, that would have been a mess)
object Party {
type Chocolate = Char
type Sticker = Any
def complain(c: Chocolate) = abort(s"You should have asked me if I wanted `$c`")
sealed trait Girl {
def willYouEat(c: Chocolate): VagueAnswer
def eat(c: Chocolate): (Rating, Girl)
_ = magic
Option[A] = Some[A] | None
/*
O: Objects
A: Arrows
*/
O_00 = { _, X }
O_00 = { _ -> X }