From 5b7026dd0decb7efbe680aabd0805e4d7d41a4bc Mon Sep 17 00:00:00 2001
From: johnynek 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@4d8e4574
+// eval: Eval[UserUpdateResult] = cats.Later@3ec2dd0
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$11937/0x00007f9d0b02c9c8@1e0ce73f,
+// f = cats.data.ContT$$Lambda$14330/0x00007f9566678d58@4834d16d,
// index = 0
// )
// )
@@ -319,7 +319,7 @@
(userFields("id").toInt)
}
}
-// anotherEval: Eval[UserUpdateResult] = cats.Eval$$anon$5@7944bf7c
+// anotherEval: Eval[UserUpdateResult] = cats.Eval$$anon$5@4cab108f
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$11937/0x00007f9d0b02c9c8@33b1d2f8,
+// f = cats.data.ContT$$Lambda$14330/0x00007f9566678d58@31a589fa,
// index = 0
// )
// )
@@ -370,7 +370,7 @@
flatMap persistToDb flatMap publishEvent
// chainOfContinuations: ContT[Eval, UserUpdateResult, UserUpdateResult] = FromFn(
// runAndThen = Single(
-// f = cats.data.ContT$$Lambda$11941/0x00007f9d0b02d350@1df1849d,
+// f = cats.data.ContT$$Lambda$14334/0x00007f95666796e0@35d57122,
// index = 0
// )
// )
@@ -381,7 +381,7 @@ updateUserModel
finalResult
}
}
-// eval: Eval[UserUpdateResult] = cats.Eval$$anon$5@1d65cf00
+// eval: Eval[UserUpdateResult] = cats.Eval$$anon$5@4434c02
eval.value
// Updated user model
diff --git a/datatypes/eval.html b/datatypes/eval.html
index 10880a6b66..6801f3eaa5 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@5820f16e
+// lazyEval: Eval[Int] = cats.Later@3dc53ebc
lazyEval.value
// Running expensive calculation...
@@ -276,7 +276,7 @@ println
("Running expensive calculation...")
1 + 2 * 3
}
-// always: Eval[Int] = cats.Always@2c752c5a
+// always: Eval[Int] = cats.Always@4975ff1e
always.value
// Running expensive calculation...
diff --git a/datatypes/freeapplicative.html b/datatypes/freeapplicative.html
index c5482658a7..3fd9b3375c 100644
--- a/datatypes/freeapplicative.html
+++ b/datatypes/freeapplicative.html
@@ -275,7 +275,7 @@
+// valid: IndexedStateT[Eval, Closed.type, Open.type, Unit] = cats.data.IndexedStateT@4998e199
val validator = prog.foldMap[FromString](compiler)
-// validator: FromString[Boolean] = cats.instances.Function1Instances$$anon$7$$Lambda$12108/0x00007f9d0a8aaa80@1096d467
+// validator: FromString[Boolean] = cats.instances.Function1Instances$$anon$7$$Lambda$14501/0x00007f95666fa000@640d2b0
validator("1234")
// res0: Boolean = false
validator("12345")
diff --git a/datatypes/freemonad.html b/datatypes/freemonad.html
index 0e07995c24..ef7b0ff31e 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@45fa4f2c
+// state: TeletypeState[Unit] = cats.data.IndexedStateT@7c94c66
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 b271df9585..0bf4953d1d 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@5d142bb1valid
correctly models that this computation can be executed only with an initial Closed
state.
+// res6: Eval[(Open.type, Unit)] = cats.Eval$$anon$1@7a103ba8
valid.run(Open)
// error: type mismatch;
@@ -483,7 +483,7 @@
valid.run(Closed)
-// res6: Eval[(Open.type, Unit)] = cats.Eval$$anon$1@122681b6
diff --git a/typeclasses/bifoldable.html b/typeclasses/bifoldable.html
index 98f23adc87..cc0e6550e3 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@6ba69df7
+// right: Eval[String] = cats.Eval$$anon$1@59d5c12
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@55476083
+// reversedRight: Eval[String] = cats.Eval$$anon$1@5d602a4b
reversedRight.value === expected
// res4: Boolean = false
diff --git a/typeclasses/bifunctor.html b/typeclasses/bifunctor.html
index d504a7f3ec..265f6d2fa9 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 = 1737195652L)
+// res0: Either[DomainError, Long] = Right(value = 1737231470L)
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 bc8161bb6e..eb8cf477da 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@7a407065
+// nelBimonad: Bimonad[NonEmptyList] = repl.MdocSession$MdocApp$$anon$1@4a2df027
diff --git a/typeclasses/contravariant.html b/typeclasses/contravariant.html
index 1e186c12d7..14787a71f7 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$12920/0x00007f9d0b2da5b0@4953b4a1
+// showSalary: Show[Salary] = cats.Show$$anon$2$$Lambda$15313/0x00007f956699fd60@20895ff4
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@2e8bd690
+// moneyOrdering: Ordering[Money] = scala.math.Ordering$$anon$5@a5ea56
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@341363ea
+// b: B = repl.MdocSession$MdocApp$B@17780bae
val a: A = b
-// a: A = repl.MdocSession$MdocApp$B@341363ea
+// a: A = repl.MdocSession$MdocApp$B@17780bae
val showA: Show[A] = Show.show(a => "a!")
-// showA: Show[A] = cats.Show$$$Lambda$12919/0x00007f9d0b2da138@3f7a9f25
+// showA: Show[A] = cats.Show$$$Lambda$15312/0x00007f956699f8e8@7d09de0f
val showB1: Show[B] = showA.contramap(b => b: A)
-// showB1: Show[B] = cats.Show$$anon$2$$Lambda$12920/0x00007f9d0b2da5b0@e2e729d
+// showB1: Show[B] = cats.Show$$anon$2$$Lambda$15313/0x00007f956699fd60@1291229a
val showB2: Show[B] = showA.contramap(identity[A])
-// showB2: Show[B] = cats.Show$$anon$2$$Lambda$12920/0x00007f9d0b2da5b0@e7ded01
+// showB2: Show[B] = cats.Show$$anon$2$$Lambda$15313/0x00007f956699fd60@10597c08
val showB3: Show[B] = Contravariant[Show].narrow[A, B](showA)
-// showB3: Show[B] = cats.Show$$$Lambda$12919/0x00007f9d0b2da138@3f7a9f25
+// showB3: Show[B] = cats.Show$$$Lambda$15312/0x00007f956699f8e8@7d09de0f
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@47942242
+// eqFoo: Eq[Foo] = cats.kernel.Eq$$anonfun$fromUniversalEquals$2@3de57771
Foo(10, "") === Foo(10, "")
diff --git a/typeclasses/semigroup.html b/typeclasses/semigroup.html
index 1e1342af50..d81b1d10c4 100644
--- a/typeclasses/semigroup.html
+++ b/typeclasses/semigroup.html
@@ -269,23 +269,23 @@
// res9: Semigroup[String] = cats.kernel.instances.StringMonoid@7329798d
import cats.Semigroup
import cats.syntax.all._
+Semigroup[Int]
-// res8: Semigroup[Int] = cats.kernel.instances.IntGroup@993450a
+// res8: Semigroup[Int] = cats.kernel.instances.IntGroup@1e97cd49
Semigroup[String]
-// res9: Semigroup[String] = cats.kernel.instances.StringMonoid@6fc06bfc
List
(++
)
and Set
(union
)...
+// res12: Semigroup[List[Foo]] = cats.kernel.instances.ListMonoid@4f5d9817
Semigroup[List[Byte]]
-// res10: Semigroup[List[Byte]] = cats.kernel.instances.ListMonoid@58ce0459
+// res10: Semigroup[List[Byte]] = cats.kernel.instances.ListMonoid@4f5d9817
Semigroup[Set[Int]]
-// res11: Semigroup[Set[Int]] = cats.kernel.instances.SetSemilattice@b1f3e36
+// res11: Semigroup[Set[Int]] = cats.kernel.instances.SetSemilattice@70ad8b92
trait Foo
Semigroup[List[Foo]]
-// res12: Semigroup[List[Foo]] = cats.kernel.instances.ListMonoid@58ce0459
combine
).
+// res13: Semigroup[(List[Foo], Int)] = cats.kernel.Monoid$$anon$2@50f0ed4b
Semigroup[(List[Foo], Int)]
-// res13: Semigroup[(List[Foo], Int)] = cats.kernel.Monoid$$anon$2@18b7914a
Example usage: Merging maps
Map
s that combines values if they share
diff --git a/typeclasses/show.html b/typeclasses/show.html
index b30748f9e6..581335f655 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@27266542"
+// res0: String = "repl.MdocSession$MdocApp$$anon$1@2f09671e"
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.