Skip to content

Instantly share code, notes, and snippets.

@lrodero
lrodero / TestingScalaCheck.scala
Last active September 15, 2015 11:19
Unexpected behavior of ScalaCheck commands,
package com.hablapps.scalacheck.tests
import scala.util.{Try, Failure, Success}
import org.scalacheck.commands.Commands
import org.scalacheck.{Gen, Prop}
import org.scalacheck.Arbitrary._
// SYSTEM TO TEST: VENDING MACHINE OF SOFT DRINKS. \\
object SoftDrink extends Enumeration {
//> using scala "2.13.11"
//> using lib "org.typelevel::cats-effect::3.5.1"
import cats.effect.{Async, Deferred, ExitCode, IO, IOApp, Ref, Sync}
import cats.effect.std.Console
import cats.instances.list._
import cats.syntax.all._
import java.util.concurrent.ScheduledThreadPoolExecutor
import scala.collection.immutable.Queue
//> using scala "2.13.11"
//> using lib "org.typelevel::cats-effect::3.5.1"
import cats.effect._
import cats.effect.std.{Console, Queue}
import cats.instances.list._
import cats.syntax.all._
object ProducerConsumerWithStdQueue extends IOApp {
@lrodero
lrodero / SimpleMapRef.scala
Last active March 10, 2024 12:46
Using cats-effect's MapRef, simple
//> using scala 3.3
//> using dep org.typelevel::cats-effect:3.5.4
import cats.effect.{IO, IOApp}
import cats.effect.std.MapRef
object SimpleMapRef extends IOApp.Simple:
private val simpleSample =
for
@lrodero
lrodero / ConcurrencyMapRef.scala
Last active March 10, 2024 12:44
Using cats-effect's MapRef, concurrent
//> using scala 3.3
//> using dep org.typelevel::cats-effect:3.5.4
import cats.syntax.all.*
import cats.effect.{IO, IOApp}
import cats.effect.std.MapRef
object ConcurrencyMapRef extends IOApp.Simple:
private val concurrencySample =
@lrodero
lrodero / FullControlMapRef.scala
Last active March 10, 2024 12:45
Using cats-effect's MapRef, full control
//> using scala 3.3
//> using dep org.typelevel::cats-effect:3.5.4
import cats.syntax.all.*
import cats.effect.{IO, IOApp}
import cats.effect.std.MapRef
import java.util.concurrent.{ConcurrentHashMap => JConcurrentHashMap}
object FullControlMapRef extends IOApp.Simple:
@lrodero
lrodero / DiningPhilosophers.scala
Last active March 24, 2024 10:59
Implementation of the dining philosophers problem using Cats Effect and Scala 3
//> using scala 3.3
//> using dep org.typelevel::cats-effect:3.5.4
import cats.effect.std.{Random, Semaphore}
import cats.syntax.all.*
import cats.effect.{IO, IOApp}
import scala.concurrent.duration.*
object DiningPhilosophers extends IOApp.Simple:
// Licensed under the Apache License, Version 2.0: http: //www.apache.org/licenses/LICENSE-2.0
// Microlib that implements retries for cats-effect (CE). Note that at the time this code was
// developed no retries functionality was included in the latest version of CE (3.5.4). Newer
// versions can have such functionality, if so it's recommended to use it instead.
// Code developed in this blog entry 'Micro library for retries in cats-effect using Scala extensions':
// https://lrodero.hashnode.dev/micro-library-for-retries-in-cats-effect-using-scala-extensions
// Run using: