Skip to content

Instantly share code, notes, and snippets.

View insdami's full-sized avatar

Damian Albrun insdami

View GitHub Profile
@insdami
insdami / Pagination.scala
Last active February 11, 2020 18:37
http4s pagination
import cats._
import cats.implicits._
import fs2.Stream
import org.http4s.client.Client
import org.http4s.headers.{Link, LinkValue}
import org.http4s.{Request, Response}
object Pagination {
type PaginationStrategy[F[_], S, O] = Option[S] => F[(O, Option[S])]
@insdami
insdami / H2Setup.scala
Created November 26, 2017 13:07
Clean up
abstract class H2Setup extends FlatSpecLike with BeforeAndAfterAll {
val table: Update0
val insertData: ConnectionIO[Int]
val h2Transactor: IO[H2Transactor[IO]] =
H2Transactor[IO]("jdbc:h2:mem:users;MODE=PostgreSQL;DB_CLOSE_DELAY=-1", "sa", "")
override def beforeAll(): Unit = {
super.beforeAll()
@insdami
insdami / IO.scala
Created August 12, 2016 09:12 — forked from jdegoes/IO.scala
A pedagogical implementation of the IO monad in Scala in 14 LOC
case class IO[A](unsafePerformIO: () => A) {
def map[B](ab: A => B): IO[B] = IO(() => ab(unsafePerformIO()))
def flatMap[B](afb: A => IO[B]): IO[B] =IO(() => afb(unsafePerformIO()).unsafePerformIO())
def tryIO(ta: Throwable => A): IO[A] =
IO(() => IO.tryIO(unsafePerformIO()).unsafePerformIO() match {
case Left(t) => ta(t)
case Right(a) => a
})
}
object IO {