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.concurrent | |
import cats.effect.{IO, IOApp} | |
import cats.implicits.catsSyntaxFlatMapOps | |
object ParTraverseApp extends IOApp.Simple { | |
override def run: IO[Unit] = { | |
def parTraverse[A, B](as: List[A])(f: A => IO[B]): IO[List[B]] = | |
as.map(a => f(a).start) | |
.foldLeft(IO.pure(List.empty[B]))((ioList, ioFibre) => |
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 java.util.*; | |
public class ListMapDeepCopy { | |
static <A, B> void deepCopy(List<Map<A,B>> target, List<Map<A,B>> source ) { | |
target.clear(); | |
source.forEach(m -> target.add(new HashMap<>(m))); | |
} | |
public static void main(String[] args) { | |
Map<String, Integer> foobar1 = new HashMap<>(); |
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.fp.dojo2.fpis.iostream | |
import org.teckhooi.fp.dojo2.fpis.iostream.Process.{Await, Emit, Halt} | |
sealed trait Process[I, O] { | |
import Process._ | |
def apply(s: LazyList[I]): LazyList[O] = this match { | |
case Halt() => LazyList() |
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
case class Config(name: String, age: Int) | |
case class Name(firstName: String, lastName: String) | |
case class Age(age: Int) extends AnyVal | |
case class Person(name: Name, age: Age) | |
object Configs: | |
type Configured[T] = Config ?=> T | |
def config: Configured[Config] = summon[Config] | |
object Exceptions: |
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
// Non recursive data structure | |
trait Functor[F[_]] { | |
def map[A, B](fa: F[A])(f: A => B): F[B] | |
} | |
sealed trait ExpressionF[A] | |
case class ValueF[A](v: Int) extends ExpressionF[A] | |
case class AddF[A](e1: A, e2: A) extends ExpressionF[A] | |
case class MultF[A](e1: A, e2: A) extends ExpressionF[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
package org.teckhooi | |
import cats.effect.{ExitCode, IO, IOApp} | |
import cats.effect.IO.ioParallel // requires for UptimeService[IO] | |
import cats.{Id, Monad, Parallel, Show} | |
import cats.syntax.parallel._ | |
import cats.syntax.functor._ | |
import cats.syntax.traverse._ // requires for traverse | |
import cats.syntax.show._ | |
import cats.syntax.flatMap._ // requires for UptimeService[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
package org.teckhooi | |
import atto.Atto._ | |
import atto._ | |
import cats._ | |
import cats.data.Kleisli | |
import cats.effect._ | |
import cats.free.Cofree | |
import cats.implicits._ | |
import doobie._ |
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 scala.language.implicitConversions | |
trait Show[A] { | |
def show(a: A): String | |
} | |
trait ShowOps { | |
def show: 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
package org.teckhooi.foo; | |
import java.util.Objects; | |
public class WhosFirst { | |
static private Long t1 = null; | |
static private Long t2 = null; | |
static private Object lock = new Object(); | |
static private long startMillis = 0; |
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.bar; | |
import java.util.Map; | |
import java.util.Objects; | |
public class Leaf implements Tree { | |
private String value; | |
public Leaf(String value) { | |
this.value = value; |