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
| // Higher kinded type example | |
| object HK1 extends App{ | |
| // Container C must take a type parameter | |
| trait Maker[C[_]] { | |
| def apply(i: Int): C[Int] | |
| } | |
| implicit object MakerList extends Maker[List] { |
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 monocle.{Iso, Prism} | |
| import monocle.macros.syntax.lens._ | |
| import monocle.macros.GenIso | |
| object LensApp extends App{ | |
| case class Street(number: Int, name: String) | |
| case class Address(city: String, street: Street, postcode: Option[String]=None) | |
| case class Company(name: String, address: Address) |
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 example | |
| trait Functor[F[_]] { | |
| def map[A, B](fa: F[A])(f: A => B): F[B] | |
| def lift[A, B](f: A => B): F[A] => F[B] = map(_)(f) | |
| } | |
| object Functor { | |
| def apply[F[_] : Functor]: Functor[F] = implicitly[Functor[F]] |
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
| object MyMonoid extends App { | |
| import scala.collection.immutable.HashMap | |
| trait Monoid[A] { | |
| def empty: A | |
| def combine(x: A, y: A): A | |
| } | |
| object Monoid { |
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 Numeric.Implicits._ | |
| import Ordering.Implicits._ | |
| def sumGreaterThanOrEquals[T](xs: List[T], max: T)(implicit num: Numeric[T]): Boolean = { | |
| @tailrec | |
| def inner(xs: List[T], accum: T): Boolean = { | |
| xs match { | |
| case x :: tail => if (accum+x>= max) true else inner(tail, accum+x) | |
| case Nil => false |
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 zio._ | |
| import zio.clock._ | |
| import zio.console._ | |
| import zio.duration._ | |
| import java.util.concurrent.TimeUnit | |
| object Sem1 extends scala.App{ | |
| val runtime = Runtime.default |
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.effect.IO | |
| import com.twitter.app.Flag | |
| import com.twitter.finagle.http.{Request, Response} | |
| import com.twitter.finagle.{Http, ListeningServer, Service} | |
| import com.twitter.server.TwitterServer | |
| import com.twitter.util.Await | |
| import io.finch.catsEffect._ | |
| import io.finch._ |
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
| val m=Map("one"->1, "two"->2) | |
| println(m) | |
| // Map(one -> 1, two -> 2) | |
| val newmap=m.updatedWith("one")(_.map(_+10)) | |
| println(newmap) |
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
| // run up Tor Browser first for it it kick off Tor Proxy) | |
| import java.net.{InetSocketAddress, URL} | |
| import java.net.Proxy | |
| object TryTorSocks extends App { | |
| val sockAddr = new InetSocketAddress("localhost", 9150) | |
| val proxy = new Proxy(Proxy.Type.SOCKS, sockAddr) | |
| val url = new URL("https://check.torproject.org/") |
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._ | |
| import cats.data._ | |
| import cats.implicits._ | |
| // Example usage of the Cats Foldable FoldM function | |
| object FoldableFoldMExample extends App{ | |
| def addIfNotTooBig(acc: Int, x: Int): Option[Int] = if (x > 8) none[Int] else (acc + x).some |