Release | 2.12 | 2.13 | 3.0.0 | |
---|---|---|---|---|
Log4cats (CE2) | 1.3.1 | ✅ | ✅ | ✅ |
Log4cats (CE3) | 2.1.1 | ✅ | ✅ | ✅ |
Keypool (CE2) | 0.3.5 | ✅ | ✅ | ✅ |
Keypool (CE3) | 0.4.5 | ✅ | ✅ | ✅ |
Unique (CE2) - CE3 is built-in | 2.1.5 | ✅ | ✅ | ✅ |
Vault (CE2) | 2.1.13 | ✅ | ✅ | ✅ |
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.effect._ | |
import java.nio.channels.AsynchronousSocketChannel | |
import java.nio.ByteBuffer | |
import java.net.InetSocketAddress | |
import java.nio.channels.{AsynchronousSocketChannel, CompletionHandler} | |
import java.nio.{Buffer, ByteBuffer} | |
object Main extends IOApp { | |
def run(args: List[String]): IO[ExitCode] = { |
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 ResourceLeak { | |
def leak[F[_]: Sync, G[_]: Async, A](resource: Resource[G, A]): F[G[A]] = { | |
Ref.in[F, G, Option[Deferred[G, A]]](None).map{ref => | |
def initiateOrGet(withDef: Option[Deferred[G, A]] = None): G[A] = Concurrent[G].uncancelable(poll => | |
ref.modify{ | |
case s@Some(a) => (s: Option[Deferred[G, A]], a.get) | |
case None => withDef match { | |
case s@Some(deferred) => (s, poll(resource.allocated.flatTap{ case (a, _) => deferred.complete(a).void}.map(_._1)).onCancel(ref.set(None)).onError{ case _ => ref.set(None)}) | |
case None => (None, poll(Deferred[G, A].map(_.some).flatMap(initiateOrGet(_)))) |
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._ | |
import cats.implicits._ | |
import cats.effect._ | |
import cats.effect.implicits._ | |
import scala.concurrent.duration._ | |
import io.chrisdavenport.mapref._ | |
trait SetOnceCache[F[_], K, V]{ | |
def get(k: K): F[V] |
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
package io.chrisdavenport.http4s.directive | |
import cats._ | |
import cats.data._ | |
import org.http4s._ | |
import cats.effect._ | |
import org.http4s._ | |
import org.http4s.implicits._ | |
import cats.syntax.all._ | |
import cats.effect.std._ |
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.effect._ | |
trait FiberLocal[F[_], A]{ | |
def get: F[A] | |
def set(value: A): F[Unit] | |
def reset: F[Unit] |
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 java.nio.file.Paths | |
import cats.effect.IOApp | |
import cats.effect.{ExitCode, IO} | |
import cats.syntax.all._ | |
object Main extends IOApp { | |
// Will be noticeably cleaner on fs2 3 | |
def run(args: List[String]): IO[ExitCode] = { | |
import cats.effect._ | |
Blocker[IO].use(blocker => |
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
/** | |
* Note `Opt[Opt[A]]` is always a lie, and can and should be flattened to `Opt[A]` | |
* | |
* Any layer of `Opt` is equivalent to `| Null`, which in terms of union types | |
* means that more than 1 layer of `| Null` is the same as the first, so don't | |
* attempt to use this with more than 1 layer, | |
* | |
* If you want more than 1 layer ever, you should probably use Option. | |
* You should probably use Option regardless, Some(None) is a meaningful type, and there is | |
* no way to represent that with this type. |
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._ | |
import cats.syntax.all._ | |
import cats.effect._ | |
import cats.effect.syntax.all._ | |
import org.http4s._ | |
import org.http4s.implicits._ | |
import org.http4s.ember.server._ | |
import scala.concurrent.duration._ | |
object Main extends IOApp { |
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 AddI { | |
def addIEarly(x: Int, i: Int): Int = { | |
require(x >= 0, "addIEarly: x must be positive") | |
require(i >= 0, "addIEarly: i must be positive") | |
val reset = i - 1 | |
@scala.annotation.tailrec def go(x: Int, pos: Int, acc: Int): Int = { | |
println(s"go: x-$x acc-$acc, pos:$pos") | |
(x, pos) match { | |
case (0, _) => acc | |
case (other, 0) => go(other-1, reset, acc + other) |