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
//> using scala 3.6.3 | |
import scala.deriving.Mirror | |
import scala.compiletime.{erasedValue} | |
/** Type-level function that transforms a type-level tuple of types | |
* into a corresponding tuple of List[...] at the value level. | |
* | |
* E.g., if Ts is (T1, T2, T3), Partitioned[Ts] is (List[T1], List[T2], List[T3]). | |
*/ |
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
//> using scala 3 | |
//> using dep "dev.zio::zio:2.1.6" | |
import zio.* | |
import zio.internal.FiberRuntime | |
import java.util.UUID | |
trait TaskManager { | |
def add(task: Task[Unit]): UIO[UUID] | |
def stop(id: UUID): UIO[Unit] |
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 vulcan.{AvroError, Codec} | |
import vulcan.generic.* | |
import zio.{ZIO, ZIOAppDefault} | |
sealed trait Foo | |
object Foo { | |
case class A(a: Int, `type`: "A" = "A") extends Foo | |
case class B(b: String, `type`: "B" = "B") extends Foo |
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, Resource} | |
import doobie.postgres.PHC | |
import doobie.{ConnectionIO, HC, LogHandler, Transactor} | |
import fs2.Pipe | |
import org.postgresql.PGNotification | |
import scala.concurrent.duration.* | |
import cats.syntax.all.* | |
import doobie.implicits.* | |
import fs2.Stream |
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
inline def f2[A, B](x: A | B): String = | |
x match | |
case a: A => "a" | |
case b: B => "b" | |
// doesn't work with subtyping | |
trait T[A] { | |
def foo(a: A): String | |
} |
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 _root_.vulcan.Codec | |
import _root_.vulcan.generic.* | |
import foo.Events.{E1, E2} | |
import fs2.kafka.* | |
import fs2.kafka.vulcan.{AvroSettings, SchemaRegistryClientSettings, avroSerializer} | |
import zio.interop.catz.* | |
import zio.interop.catz.implicits.rts | |
import zio.{Scope, Task, ZIO, ZIOAppDefault} | |
| |
object foo extends ZIOAppDefault { |
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 $ivy.`dev.zio::zio-prelude:1.0.0-RC15` | |
import zio.prelude.Newtype | |
object newtypes { | |
def derive[A, STA <: Newtype[A], F[_]](implicit ev: STA <:< Newtype[A], typeClass: F[A]): F[STA#Type] = | |
typeClass.asInstanceOf[F[STA#Type]] | |
trait Auto { | |
implicit def auto[A, STA <: Newtype[A], F[_]](implicit ev: STA <:< Newtype[A], typeClass: F[A]): F[STA#Type] = |
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 F[+A]{ | |
def ++[B >: A](that: F[B]): F[B] | |
def flatMap[B >: A](f: A => F[B]): F[B] | |
def map[B](f: A => B): F[B] | |
} | |
trait A | |
trait B | |
trait C |
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.annotation.tailrec | |
type FlatEither[A] = A match | |
case Either[l, r] => FlatEither[l] | FlatEither[r] | |
case _ => A | |
@tailrec | |
def flatEither[A](a: A): FlatEither[A] = a match | |
case e: Either[?, ?] => e match | |
case Right(r) => flatEither(r) |
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 sttp.client3.asynchttpclient.zio.{AsyncHttpClientZioBackend, SttpClient} | |
import sttp.tapir.server.ziohttp.ZioHttpInterpreter | |
import zhttp.http.RHttpApp | |
import zhttp.service.{EventLoopGroup, Server} | |
import zhttp.service.server.ServerChannelFactory | |
import zio.{Runtime, ZIO} | |
object tapir { | |
import sttp.tapir.ztapir._ |
NewerOlder