This file contains hidden or 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
trait DocumentRoute[F[_]] extends DocumentRepository[F]{ | |
def F: Monad[F] | |
val getDocuments: Route = (get & path("documents")) { | |
complete( | |
documents() | |
) | |
} |
This file contains hidden or 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
trait S3DocumentRepository[Future] { | |
def documents:Future[Seq[Document]] = ??? | |
} |
This file contains hidden or 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
trait DocumentRepository[F[_]] { | |
def documents: F[Seq[Document]] | |
} |
This file contains hidden or 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 idInterpreter extends (IndexAlg ~> Id) { | |
override def apply[A](fa: IndexAlg[A]): Id[A] = fa match { | |
case CreateIndex(_) => ().asRight[String] | |
case DeleteIndex(_) => ().asRight[String] | |
} | |
} |
This file contains hidden or 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 recreateIndex(name: String): IndexDSL[Either[String, CreateIndexResponse]] = | |
for { | |
_ <- deleteIndex(name) | |
created <- createIndex(name) | |
} yield created |
This file contains hidden or 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 IndexDSL[A] = Free[IndexAlg, A] | |
def createIndex(name: String): IndexDSL[Either[String, CreateIndexResponse]] = Free.liftF(CreateIndex(name)) | |
def deleteIndex(name: String): IndexDSL[Either[String, DeleteIndexResponse]] = Free.liftF(DeleteIndex(name)) |
This file contains hidden or 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 recreateIndex(name: String) = | |
for { | |
_ <- deleteIndex(name) | |
created <- createIndex(name) | |
} yield created |
This file contains hidden or 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
val sequentialFuture = for { | |
x <- Future { Thread sleep 1000; 10 } | |
y <- Future { Thread sleep 2000; 32 } | |
} yield x + y |
This file contains hidden or 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
sealed trait IndexAlg[A] | |
case class CreateIndex(name: String) extends IndexAlg[Either[String, CreateIndexResponse]] | |
case class DeleteIndex(name: String) extends IndexAlg[Either[String, DeleteIndexResponse]] |
This file contains hidden or 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 cats.{Id, Monad} | |
import cats.data.EitherT | |
import cats.implicits._ | |
import cats.syntax.functor._ | |
import cats.syntax.flatMap._ | |
import scala.concurrent.Future | |
import scala.concurrent.ExecutionContext.Implicits.global | |