Skip to content

Commit

Permalink
Merge branch 'main' of github.com:propensive/wisteria
Browse files Browse the repository at this point in the history
  • Loading branch information
propensive committed Aug 19, 2024
2 parents eeaad9f + 45df81c commit a9d20a7
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ object Size:
given Size[Boolean] = new Size[Boolean]:
def size(value: Boolean): Double = 1.0

given Size[Char] with
given Size[Char]:
def size(value: Char): Double = 2.0

given Size[String] = _.length.toDouble
Expand Down Expand Up @@ -415,7 +415,7 @@ object Eq extends ProductDerivation[Eq]:
(left, right) =>
fields(left):
[FieldType] => leftField =>
context.eq(leftField, complement(right))
context.equal(leftField, complement(right))
.foldLeft(true)(_ && _)
```

Expand Down Expand Up @@ -580,6 +580,25 @@ The interpretation of this implementation is that if the left and right sum type
then we use `context`, the typeclass instance that is common to both, to compare them. Otherwise, since they are
evidently different, we return `false`.

Therefore, a complete implementation of `Eq` is as simple as:
```scala
trait Eq[ValueType]:
def equal(left: ValueType, right: ValueType): Boolean

object Eq extends ProductDerivation[Eq]:
inline def join[DerivationType <: Product: ProductReflection]: Eq[DerivationType] =
(left, right) =>
fields(left):
[FieldType] => left => context.equal(left, complement(right))
.foldLeft(true)(_ && _)

inline def split[DerivationType: SumReflection]: Eq[DerivationType] =
(left, right) =>
variant(left):
[VariantType <: DerivationType] => left =>
complement(right).let(context.equal(left, _)).or(false)
```

#### Producer Sum Typeclasses

As with the `construct` method for product types, the `delegate` method is used for producer sum types which
Expand Down

0 comments on commit a9d20a7

Please sign in to comment.