Skip to content

Instantly share code, notes, and snippets.

View kareblak's full-sized avatar

Kåre Blakstad kareblak

View GitHub Profile
@AitorATuin
AitorATuin / AsyncDirective.scala
Created June 1, 2014 13:57
Jetty Async Plans with Directives Support for Unfiltered
import unfiltered.response._
import unfiltered.request._
import unfiltered.filter._
import unfiltered.directives._
import Directive._
import scala.concurrent.Future
import scala.util.Try
import javax.servlet.http.{HttpServletResponse, HttpServletRequest}
object AsyncDirective {
@etorreborre
etorreborre / argonaut.scala
Last active January 30, 2018 14:48 — forked from markhibberd/argonaut.scala
Argonaut union type / inheritance example
package argonaut.example
import argonaut._, Argonaut._
import scalaz._, Scalaz._
object UnionExample extends {
sealed trait Thing
final case class One(n: String, i: Int) extends Thing
final case class Two(n: String) extends Thing
@mpilquist
mpilquist / lastb.scala
Last active June 2, 2021 21:25
FS2 example of merging two streams and outputting the last received B value with each A value
@ def lastB[F[_]: Async, A, B]: Pipe2[F, A, B, (A, B)] = {
def go(
lastB: B,
l: ScopedFuture[F, Pull[F, Nothing, (Option[A], Handle[F,A])]],
r: ScopedFuture[F, Pull[F, Nothing, (Option[B], Handle[F,B])]]
): Pull[F,(A, B),Nothing] =
(l race r).pull flatMap {
case Left(l) => l.optional flatMap {
case None => Pull.done
case Some((None, l)) => Pull.done