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 cats.effect.{IO, IOApp} | |
object Demo extends IOApp { | |
import cats.effect._ | |
import cats.effect.concurrent._ | |
import cats.syntax.functor._ | |
import cats.syntax.parallel._ | |
import cats.instances.list._ | |
import cats.syntax.flatMap._ | |
val DemoNumbers: List[Int] = (0 until 100).toList |
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
package com.itv.sif.db | |
import cats.effect.IOApp | |
import java.util.concurrent.Executors | |
import fs2.Stream | |
import cats.syntax.functor._ | |
import scala.concurrent.ExecutionContext | |
import cats.effect._ |
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
object demo extends IOApp { | |
implicit def catsDataMonadForNested[F[_]: Monad, G[_]: Monad: Traverse]: Monad[Nested[F, G, *]] = new StackSafeMonad[Nested[F, G, *]]{ | |
override def flatMap[A, B](fa: Nested[F, G, A])(f: A => Nested[F, G, B]): Nested[F, G, B] = Nested( | |
fa.value.flatMap{ | |
Traverse[G].flatTraverse(_)(f.andThen(_.value)) | |
} | |
) |
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
case class TimeWindow(from: Instant, until: Instant) | |
implicit def tsrange: Meta[TimeWindow] = { | |
def toString(timeWindow: TimeWindow): String = | |
s"[" + | |
s"${Timestamp.from(timeWindow.from).toString}," + | |
s"${Timestamp.from(timeWindow.until).toString}" + | |
s")" |
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 org.scalatest.{FlatSpec, Matchers} | |
import cats.effect.{ContextShift, IO} | |
import com.dimafeng.testcontainers.{ForAllTestContainer, PostgreSQLContainer} | |
import doobie._ | |
import implicits._ | |
import com.itv.playground.datastore._ | |
import JsonCRUDOps._ | |
import io.circe.{Decoder, Encoder} |
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
type Id = Int | |
type Film = String | |
type Series = String | |
type Episode = String | |
type Url = String | |
case class DataBaseClient(url: Url) { | |
def get(s:String, id: Id): String = "foo" | |
} | |
object Client1 { |
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
object Model { | |
//the types don't mean anything, just faking some models. | |
type Config = Float | |
type ID = Int | |
type Age = Int | |
type DateInString = String | |
type DateSinceEpoch = Float | |
} | |
//example of api changing where the first parameter is changed. |
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
trait Pen | |
type Drawing = Unit | |
trait Side | |
case object Right extends Side | |
case object Left extends Side | |
object Drawing { | |
//pens everywhere, distracting us from the main drawing logic | |
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
object CirceDecoderCombination { | |
sealed trait Base | |
case class StringField(field1: String) extends Base | |
case class IntField(field2: Int) extends Base | |
case class FloatField(field3: Float) extends Base | |
import io.circe.{Decoder, Encoder} | |
import io.circe.generic.auto._ |
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.concurrent.duration.Duration | |
import scala.concurrent.{Await, ExecutionContext, Future} | |
object ParImpl { | |
sealed trait Par[A] { | |
def toFuture(implicit ec: ExecutionContext): Future[A] = { | |
this match { | |
case Par.Unit(f) => Future(f()) | |
case x:Par.Map2[A,_,_] => | |
for { |