There are at least 3 aspects to consider when dealing with contravariance and covariance when using container types.
def example(x: Container[T]): Container[T]
- What can you feed in
- What can point to the result
- What can the function return
//> 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]). | |
*/ |
import scala.deriving._ | |
import scala.compiletime.{erasedValue, summonInline} | |
// super primitive (but composable via typeclass derivation) JSON reader | |
trait Reader[A] { | |
def read(json: ujson.Value): A | |
} | |
object Reader { | |
given Reader[Int] = new Reader[Int] { |
object test { | |
import scalaz.zio._ | |
type UserID = String | |
case class UserProfile(name: String) | |
// The database module: | |
trait Database { | |
val database: Database.Service |
// summary : Just ONE ammonite script file to execute a load performance test using gatling ! | |
// keywords : scala, gatling, ammonite, scala, load-test, performance | |
// publish : gist | |
// authors : David Crosson | |
// license : Apache NON-AI License Version 2.0 (https://raw.githubusercontent.com/non-ai-licenses/non-ai-licenses/main/NON-AI-APACHE2) | |
// id : ea7a4259-9461-44a8-99fa-1ec6ec3c48ed | |
// created-on : 2018-09-22T07:41:07Z | |
// managed-by : https://github.com/dacr/code-examples-manager | |
// execution : scala ammonite script (http://ammonite.io/) - run as follow 'amm scriptname.sc' |
import cats.effect.ExitCase._ | |
import cats.effect.Sync | |
import cats.effect.concurrent.Ref | |
import cats.syntax.flatMap._ | |
import cats.syntax.functor._ | |
trait Tap[F[_]] { | |
def apply[A](effect: F[A]): F[A] | |
} |
import cats.Traverse | |
import cats.effect._ | |
import cats.effect.concurrent.Semaphore | |
import cats.temp.par._ | |
import cats.syntax.all._ | |
import scala.concurrent.duration._ | |
object Main extends IOApp { | |
import ParTask._ |
// Alternative to sealed abstract case class pattern for Scala 2.12.2+ | |
// Benefits: | |
// - 1 final class instead of 1 sealed class + anonymous subclass | |
// - portable to Scala 3 regardless of opaque types | |
// - less boilerplate | |
final case class Angle private (toDegrees: Int) { | |
// Define our own `copy` method to suppress synthetic one | |
// Add private to prevent it from being used | |
def copy(degrees: Int = toDegrees): Angle = Angle.fromDegrees(degrees) |
import java.util | |
import com.sksamuel.avro4s.RecordFormat | |
import org.apache.avro.generic.GenericRecord | |
import org.apache.kafka.common.serialization.{Deserializer, Serde, Serializer} | |
object Avro4s { | |
implicit class CaseClassSerde(inner: Serde[GenericRecord]) { | |
def forCaseClass[T](implicit recordFormat: RecordFormat[T]): Serde[T] = { | |
val caseClassSerializer: Serializer[T] = new Serializer[T] { |