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 Newtype #44

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

Add Newtype #44

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

Comments

@kevin-lee
Copy link
Owner

kevin-lee commented Dec 3, 2023

Summary

Add Newtype

Version

unreleased

Description

It is solely to create a newtype just like an opaque type but with a few mandatory methods and type-classes.

type Something = Something.Type
object Something extends Newtype[String] {
  given eqMyType: Eq[Something]     = deriving[Eq]
  given showMyType: Show[Something] = deriving[Show]
}

Then it can be

val something = Something("blah")
something.value
// String = blah

something.show
// String = blah

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

Something("blah") =!= Something("blah")
// Boolean = false

Something("blah") === Something("lala")
// Boolean = false

Something("blah") =!= Something("lala")
// Boolean = true
@kevin-lee kevin-lee added the task label Dec 3, 2023
@kevin-lee kevin-lee added this to the m1 milestone Dec 3, 2023
@kevin-lee kevin-lee self-assigned this Dec 3, 2023
kevin-lee added a commit that referenced this issue Dec 3, 2023
kevin-lee added a commit that referenced this issue Dec 3, 2023
kevin-lee added a commit that referenced this issue Dec 3, 2023
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