Skip to content

Commit

Permalink
doc correction
Browse files Browse the repository at this point in the history
  • Loading branch information
antognini committed Jul 12, 2023
1 parent 51e98a8 commit af01225
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
19 changes: 11 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ Eq instances can be obtained in the following ways:

Verified equality for composed case classes via type class derivation:
```scala
case class Email( address:String) derives Eq
case class Email(address: String) derives Eq

// Only compiles because class Email derives Eq
case class Person(
Expand All @@ -123,7 +123,7 @@ person == person

Verified equality for composed case classes with type parameters via type class derivation:
```scala
case class Email( address:String) derives Eq
case class Email(address: String) derives Eq

// Only compiles because the type parameter A is declared with a context bound [A: Eq]
case class Person[A: Eq](
Expand All @@ -134,16 +134,19 @@ case class Person[A: Eq](
// Only compiles because class Email derives Eq
val person = Person("Alice", Email("[email protected]"))

// Only compiles because class Person derives Eq
person == person
```

Verified equality for an existing arbitrary class with a given using the same derivation mechanism:
```scala
// Only compiles because SomeProduct conforms to the equality rules
given Eq[SomeProduct] = Eq.derived
enum Weekday:
case Monday, Tuesday, Wednesday // ...

// Only compiles with the given instance above
SomeProduct() == SomeProduct()
given Eq[Weekday] = Eq.derived

// Only compiles because given Eq type class instance for Weekday is in scope
Weekday.Monday == Weekday.Monday
```


Expand Down Expand Up @@ -229,7 +232,7 @@ import java.time.{LocalDate, LocalDateTime}
val now = LocalDateTime.now
val later = LocalDateTime.now

// Compiles out of the box
// Only compiles because given Eq type class instance for LocalDateTime is in scope
now == later

val today = LocalDate.now
Expand Down Expand Up @@ -439,7 +442,7 @@ myDay == myDay
To guarantee the build has `-language:strictEquality` enabled, include this in your sources:

```scala
// Does not need to be called, it fails to compile with strict equality turned off
// Fails to compile if strict equality is disabled
checkStrictEqualityBuild()
```

Expand Down
1 change: 1 addition & 0 deletions examples/src/main/scala/examples/EqApply.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import scala.annotation.nowarn
contact: Email,
) derives Eq:

// To be documented in README.md
// Only compiles because enum MailPolicy derives Eq
def mailPolicy: MailPolicy = Eq:

Expand Down
1 change: 1 addition & 0 deletions examples/src/main/scala/examples/Quickstart.scala
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ def verified_equality_for_composed_case_classes_with_type_parameters_via_type_cl
// Only compiles because class Email derives Eq
val person = Person("Alice", Email("[email protected]"))

// Only compiles because class Person derives Eq
person == person

case class SomeProduct()
Expand Down

0 comments on commit af01225

Please sign in to comment.