Created
January 19, 2018 15:26
-
-
Save OlegYch/0539834836492330d75b0022b8e0bac5 to your computer and use it in GitHub Desktop.
scalaz monad for slick dbio
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 scala.language._ | |
import slick.dbio.{DBIOAction, Effect, NoStream, DBIO} | |
import scalaz.Leibniz.refl | |
import scalaz.{Monad, Unapply} | |
import scalaz.Scalaz._ | |
implicit def dbioActionMonad[E <: Effect] | |
: Monad[({ type M[A] = DBIOAction[A, NoStream, E] })#M] = | |
new Monad[({ type M[A] = DBIOAction[A, NoStream, E] })#M] { | |
override def point[A](x: => A) = | |
DBIOAction.successful(x) | |
override def bind[A, B](fa: DBIOAction[A, NoStream, E])( | |
f: A => DBIOAction[B, NoStream, E]) = | |
fa.flatMap(f)(scala.concurrent.ExecutionContext.Implicits.global) | |
} | |
//Unapply instance for classes of DBIOAction shape, so stuff like List(1, 2).traverseU(_ => DBIO.successful(1)) works | |
implicit def unapplyMAB1X[U, | |
V, | |
TC[_[_]], | |
M0[_, _ <: U, _ <: V], | |
A0, | |
B0 <: U, | |
C0 <: V]( | |
implicit TC0: TC[({ type L[x] = M0[x, B0, C0] })#L]) | |
: Unapply[TC, M0[A0, B0, C0]] { | |
type M[X] = M0[X, B0, C0] | |
type A = A0 | |
} = | |
new Unapply[TC, M0[A0, B0, C0]] { | |
type M[X] = M0[X, B0, C0] | |
type A = A0 | |
def TC: TC[M] = TC0 | |
def leibniz = refl | |
} | |
List(1, 2).traverseU(_ => DBIO.successful(1)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://scastie.scala-lang.org/OlegYch/WNBAkm8RReCfs7iOpUBXyA