import... | What it imports |
---|---|
cats.std.type |
Typeclass instances for standard library type (think List , Option ) |
cats.syntax.type |
“Enhanced” methods for type (.toRightXor etc) |
cats.data.type |
Imports a type not part of the standard library (think Xor , Kleisli ) and its typeclass instances |
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 nm | |
import cats._ | |
import cats.implicits._ | |
import cats.data.WriterT | |
object Mocking { | |
I hereby claim:
- I am noelmarkham on github.
- I am noel (https://keybase.io/noel) on keybase.
- I have a public key whose fingerprint is 89A2 B6E9 B309 3F3A 752B 705A 2660 0E7B 872A 52AB
To claim this, I am signing this object:
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 shapeless._ | |
import shapeless.ops.hlist.IsHCons | |
object ShapelessDojo { | |
def addOneToCaseClass[C, H <: HList, E, T <: HList] | |
(c: C) | |
(implicit gen: Generic.Aux[C, H], | |
h: IsHCons.Aux[H, E, T], | |
ev: E =:= Int, |
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
scala> import org.scalacheck._ | |
import org.scalacheck._ | |
scala> val generatedFunc = Gen.resultOf[String => Int, String => Int](identity).sample.get | |
generatedFunc: String => Int = <function1> | |
scala> generatedFunc("hello") == generatedFunc("goodbye") | |
res0: Boolean = true |
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
// Given a case class where the first two elements have the same type, swap those values: | |
def swap[T, U <: HList, H1, H2, T1 <: HList, T2 <: HList](v: T)( | |
implicit // proofs: | |
// Case class T can be represented by U | |
// (U is an output, must be used as an output before using it as an input in the proofs below) | |
gen: Generic.Aux[T, U], | |
// U is composed of H1 :: T1 | |
isc1: IsHCons.Aux[U, H1, T1], |
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
scala> :paste | |
// Entering paste mode (ctrl-D to finish) | |
import org.scalacheck.Prop.forAll | |
import org.scalacheck.Properties | |
import shapeless.contrib.scalacheck._ | |
case class WebServerConfig(hostname: String, port: Int) | |
case class ApplicationConfig(webServer: WebServerConfig) |
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 FlakyFunctionTest { | |
import scalaz._ | |
import Scalaz._ | |
var state = false | |
val function: Unit => String = scalaz.Memo.immutableHashMapMemo { _ => | |
println(s"We received a call") |
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
scala> usernameToUserIdLens.get("Alan").foreach(println) | |
** SELECT ID FROM USERS WHERE NAME = Alan | |
1 | |
scala> userIdToStreetNameLens.get(1).foreach(println) | |
** SELECT STREET_NAME FROM ADDRESS WHERE USER_ID = 1 | |
High Street | |
scala> val usernameToStreetNameLens = usernameToUserIdLens >=> userIdToStreetNameLens |
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
scala> val FL = Functor[List] | |
FL: scalaz.Functor[List] = scalaz.std.ListInstances$$anon$1@575f20e3 | |
scala> val FF = Functor[Future] | |
FF: scalaz.Functor[scala.concurrent.Future] = scalaz.std.FutureInstance@678bc1a9 | |
scala> val FF_FL = FF compose FL | |
FF_FL: scalaz.Functor[[α]scala.concurrent.Future[List[α]]] = scalaz.Functor$$anon$1@49487384 | |
scala> val values = Future(List(1, 2, 3, 4, 5)) |
NewerOlder