Skip to content

Instantly share code, notes, and snippets.

@neko-kai
neko-kai / final-case-class.scala
Created August 11, 2020 20:27
Why you should always declare case classes final
case class X()
sealed trait Unrelated { def x: Int }
object App extends App {
def getX(xs: List[X]): List[Int] = {
xs.collect {
case u: Unrelated => u.x
}
@neko-kai
neko-kai / DottyImmutableTestSyntax.scala
Last active May 9, 2020 19:35
Dotty immutable test syntax
object MyTest extends Test {
val suite =
"MySuite"
> "should do x" {
assert(2 + 2 == 4)
}
> "should do y" {
assert(2 + 2 == 8)
}
@neko-kai
neko-kai / Vessel.scala
Last active May 6, 2020 13:01
obsidiansystems/vessel in Scala 2
package example
import example.Has.Has0
import example.Eq.{GEQ, Y}
import example.Vessel.{FlipAp, FlipAp0, VSum}
import scala.language.implicitConversions
final case class LS[F[_]](l: List[F[String]])
final case class LI[F[_]](l: List[F[Int]])
@neko-kai
neko-kai / TRIO.scala
Last active December 4, 2019 12:16
TRIO.scala
trait TRIO[F[-_, +_, +_]] {
def pure[A](a: A): F[Any, Nothing, A]
def fail[E](e: E): F[Any, E, Nothing]
def flatMap[R1, E1, A, R2 <: R1, E2 >: E1, B](fa: F[R1, E1, A])(fab: A => F[R2, E2, B]): F[R2, E2, B]
def catchAll[R1, E1, A, R2 <: R1, E2, A2 >: A](fa: F[R1, E1, A])(h: E1 => F[R2, E2, A2]): F[R2, E2, A2]
def bracket[R, E, A, B](acquire: F[R, E, A], release: A => F[R, Nothing, Unit], use: A => F[R, E, B]): F[R, E, B]
}
object TRIO {
@neko-kai
neko-kai / notes.md
Last active May 31, 2019 20:39
ZIO RC5 Release Notes

ZIO Core

  • Added FiberRef, a version of FiberLocal that's inherited by child fibers on forks and joins (#665) (#618)

    • Added inheritFiberRefs
  • ZStream now tracks finalization scopes as part of the stream computations. This means that resources are acquired and released more precisely as part of the stream, including across concurrency combinators such as buffer, zipWith and merge. (#906)

    • ZStream uses ZManaged as the return type for stream folds
    • Several concurrency combinators were added: ZStream#flatMapPar, ZStream.flattenPar and ZStream.mergeAll.
  • Added ZIO Tracing for the JVM - Cause now includes a ZTrace with the fiber's monadic stack trace, execution trace and traces of parent fibers at time of failure. (#849)

@neko-kai
neko-kai / PerfTest.scala
Created January 7, 2019 00:38
logstage perf tests
package com.github.pshirshov.izumi
import com.github.pshirshov.izumi.logstage.api.logger.LogRouter
import com.github.pshirshov.izumi.logstage.api.{IzLogger, Log}
object PerfTest {
final val acceptingNullRouter = new LogRouter {
override def acceptable(id: Log.LoggerId, messageLevel: Log.Level): Boolean = true
override protected def doLog(entry: Log.Entry): Unit = {}
@neko-kai
neko-kai / quantified.scala
Last active April 2, 2019 13:53
Tagless final for ZIO via quantified constraints
package quantified
import cats.Monad
import scala.language.implicitConversions
/**
* C[_] constraint applied to type F[_, _] quantified in first parameter, i.e.
*
* {{{
@neko-kai
neko-kai / StagedInjection.scala
Created August 4, 2018 22:38
Naive effectful instantiation in distage
import distage._
import distage.config._
import com.typesafe.config._
import scala.concurrent.{Await, Future}
import scala.concurrent.duration.Duration
import scala.concurrent.ExecutionContext.global
case class DbConf()
case class MsgQueueConf()
@neko-kai
neko-kai / Day.kt
Last active November 3, 2018 19:56
day-kt
package com.github.kaishh.day
import arrow.*
import arrow.core.*
import arrow.data.*
import arrow.syntax.function.*
import arrow.instances.*
import arrow.typeclasses.*
/**
@neko-kai
neko-kai / MonadRandom.scala
Created June 13, 2018 15:56
difference between mtl-style and tagless final style
import cats._
import cats.implicits._
trait MonadRandom[F[_]] {
def getRandom: F[Int]
}
final case class DummyRandom[A](a: A)
final case class RealRandom[A](a: A)