Skip to content

Instantly share code, notes, and snippets.

@TimWSpence
TimWSpence / blockOn.scala
Last active April 28, 2023 13:42
Cats effect 2 nested evalOn/blockOn gotcha
import cats.implicits._
import cats.effect.{Blocker, IO, IOApp, ExitCode}
import java.util.concurrent.Executors
object Test extends IOApp {
override def run(args: List[String]): IO[ExitCode] = {
val blocker = Blocker.liftExecutorService(Executors.newCachedThreadPool())
blocker.blockOn(
for {
_ <- printThread
@danieldietrich
danieldietrich / BigFTest.md
Last active October 6, 2017 12:46
Javaslang's Future: Thread creation and ExecutorService usage

Future Test

public class BigFTest {

    public static void main(String[] args) throws Throwable {
        final long sleepMillis = 1500;

        ExecutorService executorService = Executors.newFixedThreadPool(1);
package demo
object ScalaDsl {
/*
* Defining a simplistic model for the web app DSL
*/
case class HttpRequest(path: String, headers: Map[String, String], body: Option[String])
@tpolecat
tpolecat / gist:7401433
Last active August 29, 2020 08:00
set is not a functor mkay
scala> case class Bad(a: Int) { override def equals(a:Any) = true }
scala> val f = (n:Int) => Bad(n)
scala> val g = (b:Bad) => b.a
...
scala> Set(1,2,3).map(f andThen g)
res2: scala.collection.immutable.Set[Int] = Set(1, 2, 3)
scala> Set(1,2,3).map(f).map(g)
@martintrojer
martintrojer / exprPattern.scala
Last active July 2, 2021 06:23
expression problem
object exprPattern extends App {
sealed trait Expr
case class Add(e1: Expr, e2: Expr) extends Expr
case class Sub(e1: Expr, e2: Expr) extends Expr
case class Num(n: Int) extends Expr
def value(e: Expr): Int = e match {
case Add(e1, e2) => value(e1) + value(e2)
case Sub(e1, e2) => value(e1) - value(e2)
case Num(n) => n
@retronym
retronym / low-priority-implicits.scala
Created November 7, 2009 13:00
Scala 2.8 implicit prioritisation, as discussed in: http://www.scala-lang.org/sid/7
object Low {
def low = "object Low"
def shoot = "missed!"
}
object High {
def high = "object High"
def shoot = "bulls eye!"
}