Skip to content

Instantly share code, notes, and snippets.

def canViewPluginVersion[C: PluginStore: VendorStore](account: Option[Account], p: Plugin, pv: PluginVersion): Kleisli[IO, C, Boolean] =
if (pv.status === PluginVersionPublished && (Plugin.hasMarketplaceEnabledVersion(p) || (pv.marketplaceType /== Marketplace)))
pointK[IO, C, Boolean](true)
else
account.fold(some = a => canEditPlugin(a, p), none = pointK[IO, C, Boolean](false))
import scalaz._, Free._
sealed trait Arithmetic[+A]
sealed case class Addition[A](a: Int, b: Int, f: Int => A) extends Arithmetic[A]
object Arithmetic {
implicit val ArithmeticFunctor: Functor[Arithmetic] = new Functor[Arithmetic] {
def map[A, B](fa: Arithmetic[A])(f: A => B) = fa match {
case z@Addition(_, _, g) => z.copy(f = f compose g)
}
type :+:[+A, +B] = Either[A, B]
implicit def CoproductFunctor[F[_], G[_]](implicit F: Functor[F], G: Functor[G]) =
new Functor[({type λ[α] = Either[F[α], G[α]]})#λ] {
def map[A, B](a: Either[F[A], G[A]])(f: A => B) = a match {
case Left(fa) => Left(F.map(fa)(f))
case Right(ga) => Right(G.map(ga)(f))
}
}
def initCasbah: IO[Unit] = ...
def createDb(config: MongoConfig): IO[MongoDB] = ...
def closeDb(db: MongoDB): IO[Unit] = ...
trait MongoSpec extends Spec {
var db: MongoDB = null
def connect {
db = (initCasbah >> createDb(MongoConfig(db = "pac-tests"))).unsafePerformIO
}
@purefn
purefn / gist:2939324
Created June 16, 2012 00:17
Using tagged types to create arbitrary non-empty strings for testing
sealed trait NonEmpty
implicit lazy val arbNonEmptyString: Arbitrary[String @@ NonEmpty] =
Arbitrary(arbitrary[NonEmptyList[Char]].map(_.list.mkString.asInstanceOf[String @@ NonEmpty]))
trait HttpcExpr[+A]
sealed case class HttpcResponse(status: Int, headers: Map[CI[String], List[String]], entity: InputStream)
sealed case class GET[A](uri: URI, f: HttpcResponse ⇒ A) extends HttpcExpr[A]
sealed case class ReadEntity[A](res: HttpcResponse, f: String ⇒ A) extends HttpcExpr[A]
sealed trait ChanExpr[+B]
sealed case class NewChan[A, B](f: Chan[A] ⇒ B) extends ChanExpr[B]
sealed case class ReadChan[A, B](c: Chan[A], f: A ⇒ B) extends ChanExpr[B]
sealed case class WriteChan[A, B](c: Chan[A], a: A, b: B) extends ChanExpr[B]
rwallace@ronin:~/Development/scalaz scalaz-seven$ sbt ";project core;console"
Detected sbt version 0.12.0-RC4
Using /home/rwallace/.sbt/0.12.0-RC4 as sbt dir, -sbt-dir to override.
[info] Loading project definition from /home/rwallace/Development/scalaz/project
[info] Set current project to scalaz (in build file:/home/rwallace/Development/scalaz/)
[info] Set current project to scalaz-core (in build file:/home/rwallace/Development/scalaz/)
[info] Compiling 1 Scala source to /home/rwallace/Development/scalaz/core/target/scala-2.9.2/classes...
[info] Starting scala interpreter...
[info]
Welcome to Scala version 2.9.2 (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_33).
scala> { println(1) } #:: { println(2) } #:: { println(3) } #:: Stream.empty
1
res0: scala.collection.immutable.Stream[Unit] = Stream((), ?)
scala> .iterator
res1: Iterator[Unit] = non-empty iterator
scala> .toStream
res2: scala.collection.immutable.Stream[Unit] = Stream((), ?)
trait Option[+A] {
@inline final def cata[Z](some: A => Z, none: => Z) = this match {
case Some(a) => some(a)
case None => none
}
}
object Option {
private[Option] case class Some[+A](a: A) extends Option[A]
private[Option] case object None extends Option[Nothing]
scala> val o: Option[Int] = Some(5)
o: Option[Int] = Some(5)
scala> val l: List[Int] = List(10)
l: List[Int] = List(10)
scala> l flatMap (_ => o)
res1: List[Int] = List(5)
scala> o flatMap (_ => l)