diff --git a/datatypes/contt.html b/datatypes/contt.html index ce1b56cbbb..70cbb33ecf 100644 --- a/datatypes/contt.html +++ b/datatypes/contt.html @@ -286,7 +286,7 @@

ContT

Succeeded(user.id) } } -// eval: Eval[UserUpdateResult] = cats.Later@17fae388 +// eval: Eval[UserUpdateResult] = cats.Later@48b9bf0

Finally we can run the resulting 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$11791/0x00007ff0c3fbb0e8@3388da18, +// f = cats.data.ContT$$Lambda$11614/0x00007fe9a3f6abf0@62999c9, // index = 0 // ) // ) @@ -319,7 +319,7 @@

Succeeded(userFields("id").toInt) } } -// anotherEval: Eval[UserUpdateResult] = cats.Eval$$anon$5@416816a0 +// anotherEval: Eval[UserUpdateResult] = cats.Eval$$anon$5@3c4970d6 anotherEval.value // Persisting these fields to the DB: Map(id -> 100, name -> Bob, age -> 150) @@ -336,7 +336,7 @@

// updateUserModel: ContT[Eval, UserUpdateResult, User] = FromFn( // runAndThen = Single( -// f = cats.data.ContT$$Lambda$11791/0x00007ff0c3fbb0e8@191527d3, +// f = cats.data.ContT$$Lambda$11614/0x00007fe9a3f6abf0@74f0f889, // index = 0 // ) // ) @@ -370,7 +370,7 @@

updateUserModel flatMap persistToDb flatMap publishEvent // chainOfContinuations: ContT[Eval, UserUpdateResult, UserUpdateResult] = FromFn( // runAndThen = Single( -// f = cats.data.ContT$$Lambda$11795/0x00007ff0c3fbba70@6c536dd4, +// f = cats.data.ContT$$Lambda$11618/0x00007fe9a3f6b578@7f5f31e6, // index = 0 // ) // ) @@ -381,7 +381,7 @@

finalResult } } -// eval: Eval[UserUpdateResult] = cats.Eval$$anon$5@30f3cfbe +// eval: Eval[UserUpdateResult] = cats.Eval$$anon$5@2bc98353 eval.value // Updated user model diff --git a/datatypes/eval.html b/datatypes/eval.html index a961175a70..7ed687a59f 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@d281775 +// lazyEval: Eval[Int] = cats.Later@590f15eb lazyEval.value // Running expensive calculation... @@ -276,7 +276,7 @@

println("Running expensive calculation...") 1 + 2 * 3 } -// always: Eval[Int] = cats.Always@43705e92 +// always: Eval[Int] = cats.Always@6d41ce9a always.value // Running expensive calculation... diff --git a/datatypes/freeapplicative.html b/datatypes/freeapplicative.html index f7d39306be..249fc20c7e 100644 --- a/datatypes/freeapplicative.html +++ b/datatypes/freeapplicative.html @@ -275,7 +275,7 @@

val validator = prog.foldMap[FromString](compiler)
-// validator: FromString[Boolean] = cats.instances.Function1Instances$$anon$7$$Lambda$11951/0x00007ff0c4038bd0@402e09bb
+// validator: FromString[Boolean] = cats.instances.Function1Instances$$anon$7$$Lambda$11774/0x00007fe9a3ff03d0@30feb8c2
 validator("1234")
 // res0: Boolean = false
 validator("12345")
diff --git a/datatypes/freemonad.html b/datatypes/freemonad.html
index dd038970cc..e99299d607 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@284e3c90 +// state: TeletypeState[Unit] = cats.data.IndexedStateT@194747ff 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 3b88902d86..d13f1f6f87 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@7becc039

+// valid: IndexedStateT[Eval, Closed.type, Open.type, Unit] = cats.data.IndexedStateT@78e4900a

Note that the inferred type of valid correctly models that this computation can be executed only with an initial Closed state.

valid.run(Open)
 // error: type mismatch;
@@ -483,7 +483,7 @@ 

valid.run(Closed) -// res6: Eval[(Open.type, Unit)] = cats.Eval$$anon$1@73776a

+// res6: Eval[(Open.type, Unit)] = cats.Eval$$anon$1@74b77cbf diff --git a/typeclasses/bifoldable.html b/typeclasses/bifoldable.html index e533932268..43030c1904 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@3d7d9f17 +// right: Eval[String] = cats.Eval$$anon$1@2951d4ec 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@25122028 +// reversedRight: Eval[String] = cats.Eval$$anon$1@710a0f11 reversedRight.value === expected // res4: Boolean = false diff --git a/typeclasses/bifunctor.html b/typeclasses/bifunctor.html index 0cdfcec0e9..3ef4d0e021 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 = 1706103679L) +// res0: Either[DomainError, Long] = Right(value = 1706114896L)

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)

There is no 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 c8bb4aa26a..b9e6708a9d 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@38a11c2c +// nelBimonad: Bimonad[NonEmptyList] = repl.MdocSession$MdocApp$$anon$1@5d6acbe1

Note the equivalence:

nelBimonad.pure(true).extract === NonEmptyList.one(true).head
 // res0: Boolean = true
diff --git a/typeclasses/contravariant.html b/typeclasses/contravariant.html index dd8c6d249d..d7d0135e56 100644 --- a/typeclasses/contravariant.html +++ b/typeclasses/contravariant.html @@ -246,7 +246,7 @@

implicit val showSalary: Show[Salary] = showMoney.contramap(_.size) -// showSalary: Show[Salary] = cats.Show$$anon$2$$Lambda$12723/0x00007ff0c42f46b8@2231910e +// showSalary: Show[Salary] = cats.Show$$anon$2$$Lambda$12546/0x00007fe9a427bb08@3ff4a217 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@7afb5c38 +// moneyOrdering: Ordering[Money] = scala.math.Ordering$$anon$5@f1ccf7d 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@6b681593 +// b: B = repl.MdocSession$MdocApp$B@461a4e30 val a: A = b -// a: A = repl.MdocSession$MdocApp$B@6b681593 +// a: A = repl.MdocSession$MdocApp$B@461a4e30 val showA: Show[A] = Show.show(a => "a!") -// showA: Show[A] = cats.Show$$$Lambda$12722/0x00007ff0c42f4240@6a6f3e06 +// showA: Show[A] = cats.Show$$$Lambda$12545/0x00007fe9a427b690@581ad606 val showB1: Show[B] = showA.contramap(b => b: A) -// showB1: Show[B] = cats.Show$$anon$2$$Lambda$12723/0x00007ff0c42f46b8@44f86ba4 +// showB1: Show[B] = cats.Show$$anon$2$$Lambda$12546/0x00007fe9a427bb08@42e43308 val showB2: Show[B] = showA.contramap(identity[A]) -// showB2: Show[B] = cats.Show$$anon$2$$Lambda$12723/0x00007ff0c42f46b8@64c2e59f +// showB2: Show[B] = cats.Show$$anon$2$$Lambda$12546/0x00007fe9a427bb08@2b6a6b0e val showB3: Show[B] = Contravariant[Show].narrow[A, B](showA) -// showB3: Show[B] = cats.Show$$$Lambda$12722/0x00007ff0c42f4240@6a6f3e06 +// showB3: Show[B] = cats.Show$$$Lambda$12545/0x00007fe9a427b690@581ad606

Subtyping relationships are "lifted backwards" by contravariant functors, such that if F is a lawful contravariant functor and B <: A then F[A] <: F[B], which is expressed by Contravariant.narrow.

diff --git a/typeclasses/eq.html b/typeclasses/eq.html index 1e373b2c43..be9026d998 100644 --- a/typeclasses/eq.html +++ b/typeclasses/eq.html @@ -257,7 +257,7 @@

Eq

implicit val eqFoo: Eq[Foo] = Eq.fromUniversalEquals -// eqFoo: Eq[Foo] = cats.kernel.Eq$$anonfun$fromUniversalEquals$2@326fe3 +// eqFoo: Eq[Foo] = cats.kernel.Eq$$anonfun$fromUniversalEquals$2@16e9f2e8 Foo(10, "") === Foo(10, "") diff --git a/typeclasses/foldable.html b/typeclasses/foldable.html index 64e20dd3b5..8041826d55 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@6322808a +// prints: Eval[Unit] = cats.Eval$$anon$4@5bb1e522 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 37f14fb963..b6036e5fdf 100644 --- a/typeclasses/semigroup.html +++ b/typeclasses/semigroup.html @@ -269,23 +269,23 @@

import cats.Semigroup import cats.syntax.all._
Semigroup[Int]
-// res8: Semigroup[Int] = cats.kernel.instances.IntGroup@3f363c9e
+// res8: Semigroup[Int] = cats.kernel.instances.IntGroup@1fd0fb98
 Semigroup[String]
-// res9: Semigroup[String] = cats.kernel.instances.StringMonoid@6c11da80
+// res9: Semigroup[String] = cats.kernel.instances.StringMonoid@5a4639db

Instances for type constructors regardless of their type parameter such as List (++) and Set (union)...

Semigroup[List[Byte]]
-// res10: Semigroup[List[Byte]] = cats.kernel.instances.ListMonoid@7bb87442
+// res10: Semigroup[List[Byte]] = cats.kernel.instances.ListMonoid@6aacc6ce
 Semigroup[Set[Int]]
-// res11: Semigroup[Set[Int]] = cats.kernel.instances.SetSemilattice@5512b1d2
+// res11: Semigroup[Set[Int]] = cats.kernel.instances.SetSemilattice@9bc3847
 
 trait Foo
 Semigroup[List[Foo]]
-// res12: Semigroup[List[Foo]] = cats.kernel.instances.ListMonoid@7bb87442
+// res12: Semigroup[List[Foo]] = cats.kernel.instances.ListMonoid@6aacc6ce

And instances for type constructors that depend on (one of) their type parameters having instances such as tuples (pointwise combine).

Semigroup[(List[Foo], Int)]
-// res13: Semigroup[(List[Foo], Int)] = cats.kernel.Monoid$$anon$2@5b4eb522
+// res13: Semigroup[(List[Foo], Int)] = cats.kernel.Monoid$$anon$2@11281ed3

Example usage: Merging maps

Consider a function that merges two Maps that combines values if they share diff --git a/typeclasses/show.html b/typeclasses/show.html index f10ffaabd4..b2874f95ab 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@53b018ac"
+// res0: String = "repl.MdocSession$MdocApp$$anon$1@73eec040"

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.

@@ -245,12 +245,12 @@

Show

case class Person(name: String, age: Int) implicit val showPerson: Show[Person] = Show.show(person => person.name) -// showPerson: Show[Person] = cats.Show$$$Lambda$12722/0x00007ff0c42f4240@3e683624 +// showPerson: Show[Person] = cats.Show$$$Lambda$12545/0x00007fe9a427b690@52c6e553 case class Department(id: Int, name: String) implicit val showDep: Show[Department] = Show.fromToString -// showDep: Show[Department] = cats.Show$$$Lambda$11790/0x00007ff0c3f85290@700c4274 +// showDep: Show[Department] = cats.Show$$$Lambda$11613/0x00007fe9a3f34e90@3d1ef7b6

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.