kotools / types

Explicit types for Kotlin Multiplatform.
https://types.kotools.org
MIT License
90 stars 6 forks source link

✨ Making `EmailAddress` comparable alphabetically #595

Closed LVMVRQUXL closed 8 months ago

LVMVRQUXL commented 8 months ago

📝 Description

Similarly to the NotBlankString type, we would like to make the EmailAddress type comparable alphabetically by inheriting the Comparable interface.

interface EmailAddress : Comparable<EmailAddress> {
    override fun compareTo(other: EmailAddress): Int
}

Here's an example of comparing two email addresses from Kotlin code:

val first = EmailAddress.create("first@kotools.org")
val second = EmailAddress.create("second@kotools.org")
println(first < second) // true

Here's an example of comparing two email addresses from Java code:

final EmailAddress first = EmailAddress.Companion.create("first@kotools.org");
final EmailAddress second = EmailAddress.Companion.create("second@kotools.org");
System.out.println(first < second); // true

✅ Checklist

LVMVRQUXL commented 8 months ago

We should precise the checklist before marking this issue as ready.

LVMVRQUXL commented 8 months ago

We should stabilize the EmailAddress type's representation before making it comparable alphabetically.