From 854ee974b47a0be63ee191d6640e4b33488b0bac Mon Sep 17 00:00:00 2001 From: satorg Date: Sat, 28 Sep 2024 20:11:02 +0000 Subject: [PATCH] deploy: f4aec7f6e0fe9e3001234d786a86555ce31bc101 --- datatypes/contt.html | 12 ++++++------ datatypes/eval.html | 4 ++-- datatypes/freeapplicative.html | 2 +- datatypes/freemonad.html | 4 ++-- datatypes/state.html | 4 ++-- typeclasses/bifoldable.html | 4 ++-- typeclasses/bifunctor.html | 2 +- typeclasses/bimonad.html | 2 +- typeclasses/contravariant.html | 16 ++++++++-------- typeclasses/eq.html | 2 +- typeclasses/semigroup.html | 12 ++++++------ typeclasses/show.html | 6 +++--- 12 files changed, 35 insertions(+), 35 deletions(-) diff --git a/datatypes/contt.html b/datatypes/contt.html index b68516696c..c2cea25da8 100644 --- a/datatypes/contt.html +++ b/datatypes/contt.html @@ -286,7 +286,7 @@

ContT

Succeeded(user.id) } } -// eval: Eval[UserUpdateResult] = cats.Later@562f50bf +// eval: Eval[UserUpdateResult] = cats.Later@3d67d91

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$11731/0x00007f67afff5a60@7b56a701, +// f = cats.data.ContT$$Lambda$14340/0x00007fb8986539c0@c741394, // index = 0 // ) // ) @@ -319,7 +319,7 @@

Succeeded(userFields("id").toInt) } } -// anotherEval: Eval[UserUpdateResult] = cats.Eval$$anon$5@7ea3e539 +// anotherEval: Eval[UserUpdateResult] = cats.Eval$$anon$5@54df0fb2 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$11731/0x00007f67afff5a60@5b5aa832, +// f = cats.data.ContT$$Lambda$14340/0x00007fb8986539c0@3ea9ed2c, // index = 0 // ) // ) @@ -370,7 +370,7 @@

updateUserModel flatMap persistToDb flatMap publishEvent // chainOfContinuations: ContT[Eval, UserUpdateResult, UserUpdateResult] = FromFn( // runAndThen = Single( -// f = cats.data.ContT$$Lambda$11735/0x00007f67afff63e8@4a2d507d, +// f = cats.data.ContT$$Lambda$14344/0x00007fb8986585b8@68a15142, // index = 0 // ) // ) @@ -381,7 +381,7 @@

finalResult } } -// eval: Eval[UserUpdateResult] = cats.Eval$$anon$5@405fd8b1 +// eval: Eval[UserUpdateResult] = cats.Eval$$anon$5@1a46459 eval.value // Updated user model diff --git a/datatypes/eval.html b/datatypes/eval.html index a2817845cd..8394fcf624 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@73ee7160 +// lazyEval: Eval[Int] = cats.Later@5a97354a lazyEval.value // Running expensive calculation... @@ -276,7 +276,7 @@

println("Running expensive calculation...") 1 + 2 * 3 } -// always: Eval[Int] = cats.Always@790446b +// always: Eval[Int] = cats.Always@2e40dd4b always.value // Running expensive calculation... diff --git a/datatypes/freeapplicative.html b/datatypes/freeapplicative.html index 53dea5aed6..4f36860d39 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$11893/0x00007f67af866a80@508b21ca
+// validator: FromString[Boolean] = cats.instances.Function1Instances$$anon$7$$Lambda$14502/0x00007fb8986d2000@6afe488c
 validator("1234")
 // res0: Boolean = false
 validator("12345")
diff --git a/datatypes/freemonad.html b/datatypes/freemonad.html
index 0d0dc80a01..1d553141bb 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@7b8eeeea +// state: TeletypeState[Unit] = cats.data.IndexedStateT@c5d0b20 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 c8e0089af2..80a85935b2 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@63e02f0a

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

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@1b04256e

+// res6: Eval[(Open.type, Unit)] = cats.Eval$$anon$1@70fb6a18 diff --git a/typeclasses/bifoldable.html b/typeclasses/bifoldable.html index 3958d91410..b274ba54c7 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@20cb4880 +// right: Eval[String] = cats.Eval$$anon$1@6bd9ce3a 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@3a01eb99 +// reversedRight: Eval[String] = cats.Eval$$anon$1@1e7ba8cb reversedRight.value === expected // res4: Boolean = false diff --git a/typeclasses/bifunctor.html b/typeclasses/bifunctor.html index 2cfe608042..65cbdcede3 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 = 1727454419L) +// res0: Either[DomainError, Long] = Right(value = 1727554233L)

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 04acb5af9a..c521b77ffa 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@2f83020 +// nelBimonad: Bimonad[NonEmptyList] = repl.MdocSession$MdocApp$$anon$1@2e7481a3

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 b479ff4563..eded90fc16 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$12683/0x00007f67b02ad008@2a94b082 +// showSalary: Show[Salary] = cats.Show$$anon$2$$Lambda$15292/0x00007fb89898d210@3f02cb67 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@630abd5c +// moneyOrdering: Ordering[Money] = scala.math.Ordering$$anon$5@608de246 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@71574e4a +// b: B = repl.MdocSession$MdocApp$B@3d311608 val a: A = b -// a: A = repl.MdocSession$MdocApp$B@71574e4a +// a: A = repl.MdocSession$MdocApp$B@3d311608 val showA: Show[A] = Show.show(a => "a!") -// showA: Show[A] = cats.Show$$$Lambda$12682/0x00007f67b02acb90@727b9188 +// showA: Show[A] = cats.Show$$$Lambda$15291/0x00007fb89898cd98@308cebc2 val showB1: Show[B] = showA.contramap(b => b: A) -// showB1: Show[B] = cats.Show$$anon$2$$Lambda$12683/0x00007f67b02ad008@2d1022cc +// showB1: Show[B] = cats.Show$$anon$2$$Lambda$15292/0x00007fb89898d210@13977ab0 val showB2: Show[B] = showA.contramap(identity[A]) -// showB2: Show[B] = cats.Show$$anon$2$$Lambda$12683/0x00007f67b02ad008@444de295 +// showB2: Show[B] = cats.Show$$anon$2$$Lambda$15292/0x00007fb89898d210@14e6a2d7 val showB3: Show[B] = Contravariant[Show].narrow[A, B](showA) -// showB3: Show[B] = cats.Show$$$Lambda$12682/0x00007f67b02acb90@727b9188 +// showB3: Show[B] = cats.Show$$$Lambda$15291/0x00007fb89898cd98@308cebc2

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 0b16bc7d9e..e7496fe378 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@40960907 +// eqFoo: Eq[Foo] = cats.kernel.Eq$$anonfun$fromUniversalEquals$2@537755bc Foo(10, "") === Foo(10, "") diff --git a/typeclasses/semigroup.html b/typeclasses/semigroup.html index 6e2d6962df..7d25eb0f7a 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@71330c33
+// res8: Semigroup[Int] = cats.kernel.instances.IntGroup@7fd7c97b
 Semigroup[String]
-// res9: Semigroup[String] = cats.kernel.instances.StringMonoid@28731f43
+// res9: Semigroup[String] = cats.kernel.instances.StringMonoid@7960a358

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@2096f5ce
+// res10: Semigroup[List[Byte]] = cats.kernel.instances.ListMonoid@2e7cdc4c
 Semigroup[Set[Int]]
-// res11: Semigroup[Set[Int]] = cats.kernel.instances.SetSemilattice@6af54718
+// res11: Semigroup[Set[Int]] = cats.kernel.instances.SetSemilattice@5f3f2447
 
 trait Foo
 Semigroup[List[Foo]]
-// res12: Semigroup[List[Foo]] = cats.kernel.instances.ListMonoid@2096f5ce
+// res12: Semigroup[List[Foo]] = cats.kernel.instances.ListMonoid@2e7cdc4c

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@34e8ce1
+// res13: Semigroup[(List[Foo], Int)] = cats.kernel.Monoid$$anon$2@1e62b2ca

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 b2476950d2..084df8dbec 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@4b63d388"
+// res0: String = "repl.MdocSession$MdocApp$$anon$1@32782f88"

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$12682/0x00007f67b02acb90@122171cc +// showPerson: Show[Person] = cats.Show$$$Lambda$15291/0x00007fb89898cd98@4de78a30 case class Department(id: Int, name: String) implicit val showDep: Show[Department] = Show.fromToString -// showDep: Show[Department] = cats.Show$$$Lambda$11726/0x00007f67affbedb8@3f255cb5 +// showDep: Show[Department] = cats.Show$$$Lambda$14335/0x00007fb89861cca8@46c74569

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.