Skip to content

Instantly share code, notes, and snippets.

View Krever's full-sized avatar

Voytek Pituła Krever

View GitHub Profile
@Krever
Krever / hkt-crud.scala
Created February 29, 2020 20:09
Higher kinded data for CRUD
sealed trait RelationUpdate[+New, +Id]
object RelationUpdate {
type Aux[E <: EntityBase] = RelationUpdate[E#New, E#Id]
case class CreateAndAdd[New](items: List[New]) extends RelationUpdate[New, Nothing]
case class Delete[Id](items: List[Id]) extends RelationUpdate[Nothing, Id]
case class Add[Id](items: List[Id]) extends RelationUpdate[Nothing, Id]
}
object H {
case class UIO[T](x: () => T) // ZIO
trait PostgresExtension {
val ctx: QuillCtx
import ctx._
implicit val jsonDecoder: Decoder[JsonObject] =
decoder(
(index, row) =>
io.circe.parser.decode[JsonObject](row.getObject(index).toString) match {
case Left(failure) => throw failure
import magnolia._
object MagnoliaTest {
trait TCA[T] {
def showA: String
}
trait TCB[T] {
def showB: String
}
//simplified logger from scala-logging
trait LoggerTakingImplicit[T] {
def log(msg: String)(implicit ev: CanLog[T])
}
trait CanLog[T] {
def logMessage(originalMsg: String, a: T): String
}
import java.io._
import io.circe._
import scala.collection.mutable.ListBuffer
import scala.io.Source
import scala.language.higherKinds
import scala.util.{Failure, Success, Try}
trait Codec[T] {
import BasicAuthAlgebra.Credentials
trait Algebra {
type Endpoint[Req, Resp]
type Request[T]
type RequestHeaders[T]
type Path[T]
type RequestBody[T]
type Method
type Response[T]