Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add deriving to derive type-class from the base type #40

Closed
kevin-lee opened this issue Dec 2, 2023 · 0 comments · Fixed by #41
Closed

Add deriving to derive type-class from the base type #40

kevin-lee opened this issue Dec 2, 2023 · 0 comments · Fixed by #41
Assignees
Labels
Milestone

Comments

@kevin-lee
Copy link
Owner

kevin-lee commented Dec 2, 2023

Summary

Add deriving to derive type-class from the base type

Version

unreleased

Description

import cats.*

type MyType = MyType.Type
object MyType extends Refined[String] {

  override inline def invalidReason(a: String): String =
    "It has to be a non-empty String but got [" + a + "]"

  override inline def predicate(a: String): Boolean = a != ""

  given eqMyType: Eq[MyType] = deriving[Eq]

  given showMyType: Show[MyType] = deriving[Show]
}
import cats.syntax.all.*

MyType("blah") === MyType("blah")
// Boolean = true

MyType("blah").show
// String = blah
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant