From 7e25d2e7a9e59bb64f1d9f41a8a521aed42c95c2 Mon Sep 17 00:00:00 2001
From: djspiewak Finally we can run the resulting Note that the inferred type of There is no Note the equivalence: Subtyping relationships are "lifted backwards" by contravariant functors, such that if Instances for type constructors regardless of their type parameter such as And instances for type constructors that depend on (one of) their type parameters having instances such
as tuples (pointwise Consider a function that merges two ContT
Succeeded(user.id)
}
}
-// eval: Eval[UserUpdateResult] = cats.Later@6dc7d6f7
+// eval: Eval[UserUpdateResult] = cats.Later@49eb5a6f
Eval
to actually execute the computation:eval.value
// Persisting updated user to the DB: User(100,Bob,150)
@@ -308,7 +308,7 @@
// anotherComputation: ContT[Eval, UserUpdateResult, Map[String, String]] = FromFn(
// runAndThen = Single(
-// f = cats.data.ContT$$Lambda$11671/0x00007f929dfb2940@7b2b2452,
+// f = cats.data.ContT$$Lambda$14106/0x00007f75336430e8@ed6c40c,
// index = 0
// )
// )
@@ -319,7 +319,7 @@
(userFields("id").toInt)
}
}
-// anotherEval: Eval[UserUpdateResult] = cats.Eval$$anon$5@30918467
+// anotherEval: Eval[UserUpdateResult] = cats.Eval$$anon$5@45cf4088
anotherEval.value
// Persisting these fields to the DB: Map(id -> 100, name -> Bob, age -> 150)
@@ -336,7 +336,7 @@ Succeeded
// updateUserModel: ContT[Eval, UserUpdateResult, User] = FromFn(
// runAndThen = Single(
-// f = cats.data.ContT$$Lambda$11671/0x00007f929dfb2940@e2d2316,
+// f = cats.data.ContT$$Lambda$14106/0x00007f75336430e8@42ff6de6,
// index = 0
// )
// )
@@ -370,7 +370,7 @@
flatMap persistToDb flatMap publishEvent
// chainOfContinuations: ContT[Eval, UserUpdateResult, UserUpdateResult] = FromFn(
// runAndThen = Single(
-// f = cats.data.ContT$$Lambda$11675/0x00007f929dfb32c8@369bdc92,
+// f = cats.data.ContT$$Lambda$14110/0x00007f7533643a70@1b8fa113,
// index = 0
// )
// )
@@ -381,7 +381,7 @@ updateUserModel
finalResult
}
}
-// eval: Eval[UserUpdateResult] = cats.Eval$$anon$5@1a5914c3
+// eval: Eval[UserUpdateResult] = cats.Eval$$anon$5@78f8c22c
eval.value
// Updated user model
diff --git a/datatypes/eval.html b/datatypes/eval.html
index 233d1757bf..90dff492ce 100644
--- a/datatypes/eval.html
+++ b/datatypes/eval.html
@@ -257,7 +257,7 @@ println
("Running expensive calculation...")
1 + 2 * 3
}
-// lazyEval: Eval[Int] = cats.Later@1d852f39
+// lazyEval: Eval[Int] = cats.Later@5f3ddfe4
lazyEval.value
// Running expensive calculation...
@@ -276,7 +276,7 @@ println
("Running expensive calculation...")
1 + 2 * 3
}
-// always: Eval[Int] = cats.Always@577258ed
+// always: Eval[Int] = cats.Always@26955ce1
always.value
// Running expensive calculation...
diff --git a/datatypes/freeapplicative.html b/datatypes/freeapplicative.html
index 933efaf2d3..4a2d09da6d 100644
--- a/datatypes/freeapplicative.html
+++ b/datatypes/freeapplicative.html
@@ -275,7 +275,7 @@
+// valid: IndexedStateT[Eval, Closed.type, Open.type, Unit] = cats.data.IndexedStateT@2914197f
val validator = prog.foldMap[FromString](compiler)
-// validator: FromString[Boolean] = cats.instances.Function1Instances$$anon$7$$Lambda$11831/0x00007f929e031118@1d3aa811
+// validator: FromString[Boolean] = cats.instances.Function1Instances$$anon$7$$Lambda$14266/0x00007f75336c0bd0@4a651cc3
validator("1234")
// res0: Boolean = false
validator("12345")
diff --git a/datatypes/freemonad.html b/datatypes/freemonad.html
index 2a8a5e5b0b..b35b7c7135 100644
--- a/datatypes/freemonad.html
+++ b/datatypes/freemonad.html
@@ -718,7 +718,7 @@
import TeletypeOps._
val state = program.foldMap(interpreter)
-// state: TeletypeState[Unit] = cats.data.IndexedStateT@21cd5d7a
+// state: TeletypeState[Unit] = cats.data.IndexedStateT@5fe8c71a
val initialState = Nil
// initialState: Nil.type = List()
val (stored, _) = state.run(initialState).value
@@ -789,7 +789,7 @@
val evaluated = hoisted.foldMap(tryInterpreter)
// evaluated: OptTry[Int] = OptionT(value = Success(value = Some(value = 12)))
diff --git a/datatypes/state.html b/datatypes/state.html
index 6745e625ed..f748878880 100644
--- a/datatypes/state.html
+++ b/datatypes/state.html
@@ -474,7 +474,7 @@
_
<- close
_ <- open
} yield ()
-// valid: IndexedStateT[Eval, Closed.type, Open.type, Unit] = cats.data.IndexedStateT@73ddd481valid
correctly models that this computation can be executed only with an initial Closed
state.
+// res6: Eval[(Open.type, Unit)] = cats.Eval$$anon$1@75cb5722
valid.run(Open)
// error: type mismatch;
@@ -483,7 +483,7 @@
valid.run(Closed)
-// res6: Eval[(Open.type, Unit)] = cats.Eval$$anon$1@64b6383c
diff --git a/typeclasses/bifoldable.html b/typeclasses/bifoldable.html
index 6c86e039f1..2cc2b9e047 100644
--- a/typeclasses/bifoldable.html
+++ b/typeclasses/bifoldable.html
@@ -338,7 +338,7 @@ s, acc) => acc.map(_ |+| s),
(s, acc) => acc.map(_ |+| s)
)
-// right: Eval[String] = cats.Eval$$anon$1@6cf139ee
+// right: Eval[String] = cats.Eval$$anon$1@19614b44
left === expected
// res2: Boolean = true
@@ -354,7 +354,7 @@
s
, acc) => acc.map(_ |+| s),
(s, acc) => acc.map(_ |+| s)
)
-// reversedRight: Eval[String] = cats.Eval$$anon$1@6ca64c53
+// reversedRight: Eval[String] = cats.Eval$$anon$1@431778fe
reversedRight.value === expected
// res4: Boolean = false
diff --git a/typeclasses/bifunctor.html b/typeclasses/bifunctor.html
index 08ee16e67c..5e1ba87626 100644
--- a/typeclasses/bifunctor.html
+++ b/typeclasses/bifunctor.html
@@ -246,7 +246,7 @@ error => DomainError(error.getMessage),
dateTime => dateTime.toEpochSecond
)
-// res0: Either[DomainError, Long] = Right(value = 1706939990L)
+// res0: Either[DomainError, Long] = Right(value = 1706994037L)
Bifunctor
also defines a convenience function called leftMap
, which is defined as follows:def leftMap[A, B, C](fab: F[A, B])(f: A => C): F[C, B] = bimap(fab)(f, identity)
rightMap
however - use map
instead. The reasoning behind this is that in Cats, the instances of
diff --git a/typeclasses/bimonad.html b/typeclasses/bimonad.html
index e278f959e4..f75e7c5b6e 100644
--- a/typeclasses/bimonad.html
+++ b/typeclasses/bimonad.html
@@ -263,7 +263,7 @@ override def tailRecM[A, B](a: A)(fn: A => NonEmptyList[Either[A, B]]): NonEmptyList[B] =
???
}
-// nelBimonad: Bimonad[NonEmptyList] = repl.MdocSession$MdocApp$$anon$1@6ff9352f
+// nelBimonad: Bimonad[NonEmptyList] = repl.MdocSession$MdocApp$$anon$1@3f277f4
diff --git a/typeclasses/contravariant.html b/typeclasses/contravariant.html
index 8eb1a782bd..db291c33be 100644
--- a/typeclasses/contravariant.html
+++ b/typeclasses/contravariant.html
@@ -246,7 +246,7 @@ nelBimonad.pure(true).extract === NonEmptyList.one(true).head
// res0: Boolean = true
implicit val showSalary: Show[Salary] = showMoney.contramap(_.size)
-// showSalary: Show[Salary] = cats.Show$$anon$2$$Lambda$12603/0x00007f929e2ec6b8@40755e03
+// showSalary: Show[Salary] = cats.Show$$anon$2$$Lambda$15038/0x00007f753394f720@59d7258f
Salary(Money(1000)).show
// res0: String = "$1000"
@@ -266,7 +266,7 @@ import scala.math.Ordered._
implicit val moneyOrdering: Ordering[Money] = Ordering.by(_.amount)
-// moneyOrdering: Ordering[Money] = scala.math.Ordering$$anon$5@4aabc285
+// moneyOrdering: Ordering[Money] = scala.math.Ordering$$anon$5@347ae410
Money(100) < Money(200)
// res3: Boolean = true
@@ -276,17 +276,17 @@
class A
class B extends A
val b: B = new B
-// b: B = repl.MdocSession$MdocApp$B@6415395f
+// b: B = repl.MdocSession$MdocApp$B@70035f81
val a: A = b
-// a: A = repl.MdocSession$MdocApp$B@6415395f
+// a: A = repl.MdocSession$MdocApp$B@70035f81
val showA: Show[A] = Show.show(a => "a!")
-// showA: Show[A] = cats.Show$$$Lambda$12602/0x00007f929e2ec240@67c78a0
+// showA: Show[A] = cats.Show$$$Lambda$15037/0x00007f753394f2a8@4a5b4cb
val showB1: Show[B] = showA.contramap(b => b: A)
-// showB1: Show[B] = cats.Show$$anon$2$$Lambda$12603/0x00007f929e2ec6b8@6c13ab2a
+// showB1: Show[B] = cats.Show$$anon$2$$Lambda$15038/0x00007f753394f720@64be128d
val showB2: Show[B] = showA.contramap(identity[A])
-// showB2: Show[B] = cats.Show$$anon$2$$Lambda$12603/0x00007f929e2ec6b8@7838f3c7
+// showB2: Show[B] = cats.Show$$anon$2$$Lambda$15038/0x00007f753394f720@707306e
val showB3: Show[B] = Contravariant[Show].narrow[A, B](showA)
-// showB3: Show[B] = cats.Show$$$Lambda$12602/0x00007f929e2ec240@67c78a0
+// showB3: Show[B] = cats.Show$$$Lambda$15037/0x00007f753394f2a8@4a5b4cb
F
is a
lawful contravariant functor and B <: A
then F[A] <: F[B]
, which is expressed by Contravariant.narrow
.Eq
implicit val eqFoo: Eq[Foo] = Eq.fromUniversalEquals
-// eqFoo: Eq[Foo] = cats.kernel.Eq$$anonfun$fromUniversalEquals$2@2b8f999d
+// eqFoo: Eq[Foo] = cats.kernel.Eq$$anonfun$fromUniversalEquals$2@53a640d6
Foo(10, "") === Foo(10, "")
diff --git a/typeclasses/foldable.html b/typeclasses/foldable.html
index 3c04cccaf0..6c2843f1ad 100644
--- a/typeclasses/foldable.html
+++ b/typeclasses/foldable.html
@@ -301,7 +301,7 @@ Foldable
// res23: Option[Boolean] = Some(value = true)
val prints: Eval[Unit] = List(Eval.always(println(1)), Eval.always(println(2))).sequence_
-// prints: Eval[Unit] = cats.Eval$$anon$4@2d59bc83
+// prints: Eval[Unit] = cats.Eval$$anon$4@27288361
prints.value
Foldable[List].dropWhile_(List[Int](2,4,5,6,7))(_ % 2 == 0)
diff --git a/typeclasses/semigroup.html b/typeclasses/semigroup.html
index 523e929aae..944ad14401 100644
--- a/typeclasses/semigroup.html
+++ b/typeclasses/semigroup.html
@@ -269,23 +269,23 @@
// res9: Semigroup[String] = cats.kernel.instances.StringMonoid@1c318cc5
import cats.Semigroup
import cats.syntax.all._
+Semigroup[Int]
-// res8: Semigroup[Int] = cats.kernel.instances.IntGroup@139986b5
+// res8: Semigroup[Int] = cats.kernel.instances.IntGroup@778d315c
Semigroup[String]
-// res9: Semigroup[String] = cats.kernel.instances.StringMonoid@47c1649b
List
(++
)
and Set
(union
)...
+// res12: Semigroup[List[Foo]] = cats.kernel.instances.ListMonoid@1e8b5e10
Semigroup[List[Byte]]
-// res10: Semigroup[List[Byte]] = cats.kernel.instances.ListMonoid@159dea30
+// res10: Semigroup[List[Byte]] = cats.kernel.instances.ListMonoid@1e8b5e10
Semigroup[Set[Int]]
-// res11: Semigroup[Set[Int]] = cats.kernel.instances.SetSemilattice@43b06752
+// res11: Semigroup[Set[Int]] = cats.kernel.instances.SetSemilattice@2e8a7fac
trait Foo
Semigroup[List[Foo]]
-// res12: Semigroup[List[Foo]] = cats.kernel.instances.ListMonoid@159dea30
combine
).
+// res13: Semigroup[(List[Foo], Int)] = cats.kernel.Monoid$$anon$2@3013acf0
Semigroup[(List[Foo], Int)]
-// res13: Semigroup[(List[Foo], Int)] = cats.kernel.Monoid$$anon$2@1cc3fdbf
Example usage: Merging maps
Map
s that combines values if they share
diff --git a/typeclasses/show.html b/typeclasses/show.html
index e8745a513a..c454748ca4 100644
--- a/typeclasses/show.html
+++ b/typeclasses/show.html
@@ -229,7 +229,7 @@ Show
Most often, this is unwanted behaviour, as the standard implementation of toString
on non case classes is mostly gibberish.
Consider the following example:
(new {}).toString
-// res0: String = "repl.MdocSession$MdocApp$$anon$1@7ccd7216"
+// res0: String = "repl.MdocSession$MdocApp$$anon$1@270699cf"
The fact that this code compiles is a design flaw of the Java API.
We want to make things like this impossible, by offering the toString
equivalent as a type class, instead of the root of the class hierarchy.
In short, Show
allows us to only have String-conversions defined for the data types we actually want.
This still may not seem useful to you, because case classes already automatically implement toString
, while show
would have to be implemented manually for each case class.
Thankfully with the help of a small library called kittens a lot of type class instances including Show
can be derived automatically!
Cats also offers Show
syntax to make working with it easier.