This file contains 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
/* | |
* Copyright 2014–2016 SlamData Inc. | |
* | |
* Licensed under the Apache License, Version 2.0 (the "License"); | |
* you may not use this file except in compliance with the License. | |
* You may obtain a copy of the License at | |
* | |
* http://www.apache.org/licenses/LICENSE-2.0 | |
* | |
* Unless required by applicable law or agreed to in writing, software |
This file contains 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 Timestamp = Long | |
type Nanos = Long | |
sealed trait Clock[A] | |
final case class CurrentMillis extends Clock[Timestamp] | |
final case class CurrentNanos extends Clock[Nanos] | |
final case class EntryId(val asString: String) extends AnyVal | |
sealed trait Audit[A] |
This file contains 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 bracket[F[_], R, A](acquire: NF[F, R])(use: R => NF[F, Option[A]], release: R => NF[F, Unit]): NF[F, A] = { | |
def go(cln: NF[F, A], p: NF[F, Option[A]]): NF[F, A] = | |
await(p) flatMap { step => | |
step.head.cata(a => emit(a) ++ go(cln, step.tail), cln ++ go(empty, step.tail)) | |
} | |
flatMap(acquire) { r => | |
val cleanup = drain[F, Unit, A](mask(release(r))) | |
onError(go(cleanup, use(r))) { e => append(cleanup, fail(e)) } | |
} |
This file contains 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 scalaz._, concurrent._ | |
trait MonadLogTask[F[_], L] extends Monad[F] with Catchable[F] { | |
def log[A](label: => L, task: Task[A]): F[A] | |
def heading[A](label: => L, fa: F[A]): F[A] | |
def liftTask[A](task: Task[A]): F[A] |
This file contains 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 runFree[S[+_], M[_]](f: S ~> M)(implicit M: Monad[M]): ({type λ[α] = Free[S, α]})#λ ~> M = | |
new (({type λ[α] = Free[S, α]})#λ ~> M) { | |
def apply[A](fr: Free[S, A]) = fr.foldMap[M, A](f) | |
} | |
def runFreeC[S[+_], M[_]](f: S ~> M)(implicit M: Monad[M]): ({type λ[α] = FreeC[S, α]})#λ ~> M = | |
new (({type λ[α] = FreeC[S, α]})#λ ~> M) { | |
def apply[A](fr: FreeC[S, A]) = fr.runM[M, A](coyo => M.map(f(coyo.fi))(coyo.k)) | |
} |
This file contains 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
object RefactorPuzzle { | |
case class IntRdr[+A](read: Int => A) { | |
def map[B](f: A => B): IntRdr[B] = | |
IntRdr(f compose read) | |
def flatMap[B](f: A => IntRdr[B]): IntRdr[B] = | |
IntRdr(n => f(read(n)).read(n)) | |
} | |
object IntRdr { |
This file contains 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 spray.testkit | |
import spray.util._ | |
import akka.actor.ActorSystem | |
trait JUnitInterface extends TestFrameworkInterface { | |
def failTest(msg: String) = throw new AssertionError(msg) | |
} | |
trait JUnitRouteTest extends RouteTest with JUnitInterface { |
This file contains 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
// Assume the esper clock has been seeded with the vimana system time on start | |
// and is being updated via the DeviceActor every 100ms when no agent is connected | |
// Someplace earlier in the class | |
var lastEvent: Option[Event] = None | |
for (event <- events) { | |
lastEvent filter (event.timestamp > _.timestamp) foreach { | |
esper.advanceClock(event.timestamp - _.timestamp) | |
} |