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
trait RNG { | |
def nextInt: (Int, RNG) // Should generate a random `Int`. We'll later define other functions in terms of `nextInt`. | |
} | |
object RNG { | |
// NB - this was called SimpleRNG in the book text | |
case class Simple(seed: Long) extends RNG { | |
def nextInt: (Int, RNG) = { | |
val newSeed = (seed * 0x5DEECE66DL + 0xBL) & 0xFFFFFFFFFFFFL // `&` is bitwise AND. We use the current seed to generate a new seed. |
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
#!/bin/sh | |
#fix_brew.sh - mcartier | |
#you can keep ur brew if u need ur formulas | |
if [ "$1" = "--keep" ]; | |
then | |
echo "actual brew not removed"; | |
else |
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
trait Functor[F[_]] { | |
def map[A,B](fa: F[A])(f: A => B): F[B] | |
def distribute[A,B](fab: F[(A, B)]): (F[A], F[B]) = | |
(map(fab)(_._1), map(fab)(_._2)) | |
def codistribute[A,B](e: Either[F[A], F[B]]): F[Either[A, B]] = e match { | |
case Left(fa) => map(fa)(Left(_)) | |
case Right(fb) => map(fb)(Right(_)) | |
} |
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
// This new data type will employ Scala’s type system to gain two static guarantees. We want our code to not compile if it violates these invariants: | |
// - If we hold a reference to a mutable object, then nothing can observe us mutat- ing it. | |
// - A mutable object can never be observed outside of the scope in which it was created. | |
/** | |
* For state thread, state transi- tion, state token, or state tag | |
* A local-effects monad. | |
* | |
* A: type of the mutable value. | |
* S: represents the ability to mutate state |
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
trait Functor[F[_]] { | |
def map[A,B](fa: F[A])(f: A => B): F[B] | |
def distribute[A,B](fab: F[(A, B)]): (F[A], F[B]) = | |
(map(fab)(_._1), map(fab)(_._2)) | |
def codistribute[A,B](e: Either[F[A], F[B]]): F[Either[A, B]] = e match { | |
case Left(fa) => map(fa)(Left(_)) | |
case Right(fb) => map(fb)(Right(_)) | |
} |
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
0x7adf277b6d4e4034fd1d230b9972824418a73566 |
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 scala.io.Source | |
def fileToString(fileName: String, folder: String): String = | |
Source.fromURL(getClass.getClassLoader.getResource(folder + fileName)).mkString |
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
/* for ammonite users | |
interp.load.ivy("org.typelevel" %% "cats-core" % "1.0.1") | |
interp.configureCompiler(_.settings.YpartialUnification.value = true) | |
@ | |
*/ | |
import cats.instances.list._ | |
import cats.instances.either._ | |
import cats.syntax.traverse._ |
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
#! /bin/sh | |
if [ $# -lt 2 ]; then | |
echo "$0 container topic" | |
exit 1 | |
fi | |
# listener | |
CONTAINER="$1" | |
TOPIC="$2" |
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
/* for ammonite users | |
interp.load.ivy("com.typesafe.akka" %% "akka-stream-kafka" % "0.22") | |
interp.load.ivy("com.typesafe.play" %% "play-json" % "2.6.7") | |
@ | |
*/ | |
import scala.concurrent.{ ExecutionContext, Future } | |
import scala.concurrent.ExecutionContext.Implicits.global | |
import scala.util.{ Failure, Success } |