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
| trait Eq[A] { | |
| def eqv(lhs: A, rhs: A): Boolean | |
| def neq(lhs: A, rhs: A): Boolean = !eqv(lhs, rhs) | |
| extension (lhs: A) { | |
| def ===(rhs: A): Boolean = eqv(lhs, rhs) | |
| def !==(rhs: A): Boolean = neq(lhs, rhs) | |
| } | |
| } |
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
| opaque type ST[S, A] = S => (A, S) | |
| object ST { | |
| extension [S, A](self: ST[S, A]) { | |
| def map[B](f: A => B): ST[S, B] = s => { | |
| val (a, s1) = self(s) | |
| (f(a), s1) | |
| } | |
| def flatMap[B](f: A => ST[S, B]): ST[S, B] = s => { | |
| val (a, s1) = self(s) |
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
| enum Json: | |
| case IntJson(value: Int) extends Json | |
| case StringJson(value: String) extends Json | |
| import Json.StringJson | |
| import Json.IntJson | |
| case class AsJson(json: Json) | |
| trait Encoder[A]: |
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
| 8.....4..72......9..4.........1.7..23.5...9...4...........8..7..17............... | |
| .........8......2..7............53...1..7...6..32...8..6.5....9..4....3......9... | |
| 12..4......5..9.1...9...5.........7.7...52.9..3......2.9.6....................... | |
| ...57..3.1......2.7...234......8...4..7..4...49.................................. | |
| ...1523........92..........1....47.8.......6............9...5.6.4.9.7............ | |
| 1.........3..2...8..96..5....53..9...1..8...26....4...3......1................... | |
| ....................4.6..21.18......3..1.2..6......81.52..7.9...................2 | |
| ...92......68.....19.......23..4.1....1...7....8.3........8..91.................. | |
| .6.5.4.3.1...9...8.........9...5...6...........................4...8...1.5.2.3.4. | |
| 7.....4...2..7..8...3..8......5..3...6..2..9...1.97..6...3....................... |
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
| package pnorvig.ipynb; | |
| import java.io.BufferedReader; | |
| import java.io.FileReader; | |
| import java.io.IOException; | |
| import java.util.ArrayList; | |
| import java.util.Arrays; | |
| import java.util.List; | |
| import java.util.concurrent.CountDownLatch; | |
| import java.util.stream.IntStream; |
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
| trait Functor[F[_]]: | |
| def map[A, B](fa: F[A])(f: A => B): F[B] | |
| trait Monad[F[_]] extends Functor[F]: | |
| def unit[A](a: A): F[A] | |
| def flatMap[A, B](fa: F[A])(f: A => F[B]): F[B] | |
| def map[A, B](fa: F[A])(f: A => B): F[B] = flatMap(fa)(x => unit(f(x))) | |
| object Monad: | |
| def apply[F[_]](using ev: Monad[F]): Monad[F] = ev |
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.concurrent.ExecutionContext.Implicits.global | |
| import scala.concurrent.* | |
| def delay(delay: Long)(id: String) = Future { | |
| Thread.sleep(delay) | |
| println(s"$id done") | |
| id | |
| } | |
| def fast(id: String) = delay(500)(id) |
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.Applicative | |
| //import cats.implicits.* | |
| /* | |
| def sequence[A, F[_], G[_]](fga: F[G[A]])(using Traverse[F], Applicative[G]): G[F[A]] = | |
| traverse(fga)(identity) | |
| trait Traverse[F[_]]: | |
| def traverse[A, B, G[_]](fa: F[A])(f: A => G[B])(using Applicative[G]): G[F[B]] | |
| */ |
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
| package th.lim.dojo3.concurrent | |
| import cats.effect.std.{Console, Random, SecureRandom} | |
| import cats.effect.{IO, IOApp} | |
| import cats.syntax.all.{toFlatMapOps, toFunctorOps} | |
| import cats.{FlatMap, Functor} | |
| /** An example of using Random[F] in additional to | |
| * https://typelevel.org/cats-effect/docs/std/random#using-random | |
| */ |
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
| package org.teckhooi; | |
| import java.time.Duration; | |
| import java.util.LinkedList; | |
| import java.util.Optional; | |
| import java.util.Queue; | |
| import java.util.UUID; | |
| import java.util.concurrent.CountDownLatch; | |
| import java.util.concurrent.ExecutorService; | |
| import java.util.concurrent.Executors; |
NewerOlder