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 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 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 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 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 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 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 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 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; |
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 FooBar { | |
// Basically Java code written using Scala syntax. Similar to using if to check for errors i.e. if (err != nil) {...} | |
object Foo extends App { | |
def addMin(a: Int, b: Int): Int = | |
if (a + b < 10) throw new Exception("Sum is less than 10") else a + b | |
def mulMin(a: Int, b: Int): Int = | |
if (a * b < 100) throw new Exception("Product is less than 100") else a * b |
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 Math.* | |
def maxDiff(xs: List[Int]): Int = | |
xs.scanLeft(Int.MaxValue)(min) | |
.tail | |
.zip(xs) | |
.map(x => x._2 - x._1) | |
.filter(_ > 0) | |
.fold(-1)(max) |