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
# Replacing Docker Desktop with Colima | |
https://jacobtomlinson.dev/posts/2022/goodbye-docker-desktop-for-mac-hello-colima/ | |
https://github.com/abiosoft/colima | |
https://github.com/abiosoft/colima/blob/main/docs/FAQ.md#docker-socket-location | |
It allows us to keep using docker and docker-compose normally, which is good for legacy scripts. | |
--- |
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.IO | |
def doThings(things: List[Int]): IO[List[Either[Throwable, String]]] = { | |
import cats.syntax.traverse._ | |
things.traverse { i => | |
if (i % 2 == 0) | |
IO(Right(s"$i = yay!")) | |
else | |
IO(Left(new Exception(s"$i = oh no!"))) |
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 scala.util.Try | |
import cats.Functor | |
import cats.Align | |
import cats.data.Ior | |
type Decimal = Int | |
type Roman = String | |
def f[F[_]: Align: Functor](fi: F[Decimal], fs: F[Roman]): F[String] = | |
import cats.syntax.align.* // <- HERE |
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 scala.util.Try | |
def compute(n: Int): Int = | |
val res = n * 10 | |
println(s">>> computing $n -> $res") | |
res | |
val n = 4 | |
val nth = 1 |
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.std.{Console, Random} | |
import cats.effect.{IO, Sync} | |
import scala.util.{Random => RandomStd} | |
/* | |
* Std lib has added `tap` and `pipe` functions for all types. | |
* With `tap` we can use a function to inspect the value without changing it. | |
* `pipe` is the equivalent of `|>` from F# or Elixir; it sends the value to a function. | |
* */ |
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
/* | |
* The good practices say we shouldn't use the same type for everything (domain, json, persistence, ...), but | |
* most of the time those types are very similar - if not exactly identical - creating a lot of duplication. | |
* | |
* Inheritance to the rescue? Nah... not very FP and even the OOP folks are aware that we should | |
* prefer composition over it. But composition has it's own challenges (Law of Demeter for instance). | |
* | |
* Let's see how the new `Export Clauses` in Scala 3 can help with that: | |
* https://docs.scala-lang.org/scala3/reference/other-new-features/export.html | |
* */ |
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.syntax.functor._ | |
// Some types | |
trait A | |
trait B | |
trait C | |
// Some functions | |
val f: A => B = ??? | |
val g: B => C = ??? |
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.IO | |
import cats.syntax.foldable._ | |
import cats.syntax.applicative._ | |
import cats.syntax.applicativeError._ | |
import cats.{ApplicativeThrow, Monad} | |
import scala.util.Try | |
// Stores type aliases for effects that have more then one type parameter | |
object Fs { |
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 eu.timepit.refined.api.{Refined, Validate} | |
import eu.timepit.refined.boolean.{And, Not} | |
import eu.timepit.refined.refineV | |
/* Domain types */ | |
final case class Customer(id: Long, name: String, age: Int) | |
final case class Order(description: String) | |
//=== |
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.Monad | |
import cats.syntax.functor.* | |
import cats.effect.IO | |
import cats.effect.unsafe.implicits.global | |
case class Frunfles(id: Long, name: String) | |
trait DatabaseConnection: | |
def exec[F[_]: Monad](op: String): F[Unit] |
NewerOlder