public class BigFTest {
public static void main(String[] args) throws Throwable {
final long sleepMillis = 1500;
ExecutorService executorService = Executors.newFixedThreadPool(1);
This file contains 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.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 |
This file contains 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
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]) |
This file contains 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
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) |
This file contains 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
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 |
This file contains 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
object Low { | |
def low = "object Low" | |
def shoot = "missed!" | |
} | |
object High { | |
def high = "object High" | |
def shoot = "bulls eye!" | |
} |