Skip to content

Instantly share code, notes, and snippets.

View Baccata's full-sized avatar

Olivier Mélois Baccata

View GitHub Profile
@Baccata
Baccata / compatibility.md
Created November 22, 2021 08:26
Data/API compatibility rules

Reasoning formally about data compatibility

Data compatibility in distributed systems is a problem that is often adressed in ad-hoc manners and suffer from bikeshedding. Developing a formal framework for reasoning about it is crucial to ensure a seamless evolution of complex systems and easy inter-connectivity of components.

Disclaimer

This gist talks specifically about backward compatibility rules. Intuitively, forward compatibility rules are the opposite of backward ones.

Defining the problem

@Baccata
Baccata / Bool.scala
Created February 25, 2015 22:44
Implementation of typelevel booleans and integers using type projections
package baccata
/**
* Inspired from Grant Beaty's Scunits
*/
trait Bool {
type branch[B,T <: B, E <: B] <: B // typelevel if-then-else
type not <: Bool
type or[R <: Bool] <: Bool
type and[R <: Bool] <: Bool
@Baccata
Baccata / repro.scala
Last active June 9, 2023 13:28
Reproduction of a http/2 specific problem with http4s-ember-server
//> using lib "org.http4s::http4s-ember-server:0.23.19"
//> using lib "org.http4s::http4s-dsl:0.23.19"
package foo
import cats.effect._
import cats.syntax.all._
import org.http4s.implicits._
import org.http4s.ember.server._
import org.http4s._
import org.http4s._
import org.http4s.syntax.all._
import smithy4s.kinds._
import smithy4s.Service
import smithy4s.http4s.SimpleRestJsonBuilder
import cats.data.OptionT
import cats.effect._
import cats.effect.syntax.all._
def precompileRoutes[Alg[_[_, _, _, _, _]]](service: Service[Alg])(
@Baccata
Baccata / tenet.scala
Created January 26, 2023 11:07
Wait for queue drain example
//> using lib "co.fs2::fs2-core:3.5.0"
import cats.effect.IOApp
import cats.effect._
import cats.effect.std.Queue
import scala.concurrent.duration._
import cats.effect.syntax.all._
import cats.syntax.all._
import cats.instances.queue
object Main extends IOApp.Simple {
@Baccata
Baccata / PolykindedMapper.scala
Last active October 24, 2022 09:33
Playing with kind-polymorphism to create a poly-kinded mapper construct.
//> using lib "org.typelevel::cats-core:2.8.0"
package foo
import cats.Functor
import cats.arrow.FunctionK
import cats.Id
import cats.ApplicativeError
import cats.MonadError
import scala.util.Try
import cats.syntax.all._
import shapeless._
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// THE IMPLICIT CLASS THAT ALLOWS TO CALL #copy ON ANY SEALED TRAIT INSTANCE
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
object copySyntax {
implicit class CopySyntax[TypeToCopy](thingToCopy: TypeToCopy) {
@Baccata
Baccata / TupleK.scala
Last active March 28, 2022 13:14
Generalised KTuple POC
//> using lib "org.typelevel::cats-core:2.7.0"
import cats.Applicative
import cats.syntax.all._
import cats.ContravariantMonoidal
import cats.InvariantMonoidal
import cats.InvariantSemigroupal
import cats.Show
import cats.~>
import cats.arrow.FunctionK
import cats.kernel.Monoid
@Baccata
Baccata / recursion.scala
Last active February 1, 2022 10:22
Baccata's recursion schemes microlib (to copy/paste when needed). Only depends on cats-core.
import cats._
import cats.syntax.all._
// format: off
/**
* A couple recursion-schemes, named in a less arcanic fashion than usual.
* These functions allow to decouple the recursive aspect of model construction
* and validation, from the domain-specific concerns.
*/
object recursion {
@Baccata
Baccata / CryptoJSFacade.scala
Last active September 14, 2021 08:23
JVM/JS/Native Platform-specific implementations of crypto functions required for implementing the AWS signature algorithm.
import scala.scalajs.js
import scala.scalajs.js.annotation.JSImport
/**
* @see https://nodejs.org/dist/latest-v7.x/docs/api/crypto.html#crypto_crypto
*/
@js.native
trait Crypto extends js.Object {
def createHash(algorithm: String): Hash = js.native