Loïc Lamarque
07/17/2023, 12:23 PMNotBlankString
or NonZeroInt
that might interest you for:
• ensuring that your data is valid through all your application
• striving for totality by reducing the possible inputs or outputs
• reducing runtime check to compile-time ones by using the compiler effectively.
My client Smartch currently use this Open Source project for defining a precise domain in their backend applications.
Like @flavio, I would like to get some feedback about what's good or bad in that project for improving it with our lovely Kotlin community.
The JetBrains team also created a #kotools-types channel that you can join for discussing about this project.
Thank you for your time and consideration! 🙏🏽flavio
07/17/2023, 1:21 PMLoïc Lamarque
07/17/2023, 2:41 PMKlitos Kyriacou
07/17/2023, 4:56 PMResult
as return values. It's a matter of personal opinion, but I would have preferred throwing exceptions, to be consistent with what the Kotlin Standard Library does.
2. It would probably be beneficial for NotBlankString
to implement CharSequence
.Loïc Lamarque
07/17/2023, 10:57 PMResult
to new builders aligned with Kotlin standards in Kotools Types 4.3.0 (see the corresponding discussion on GitHub - I'm currently splitting related issues by type). This will be a lot of work to introduce these builders without breaking the existing API, but we will implement them incrementally.
2. The API of NotBlankString
is currently incompatible with the CharSequence
: the NotBlankString.length
property returns a StrictlyPositiveInt
instead of an Int
. This choice was made for only providing an explicit API to these types. If a CharSequence
is needed and you have a NotBlankString
, you can convert it to a String
, but this is an interesting point. What benefits you see for NotBlankString
to implement the CharSequence
interface?Klitos Kyriacou
07/18/2023, 8:12 AMLoïc Lamarque
07/18/2023, 9:27 AMCharSequence
type. We may add more utilities for working with a NotBlankString
like a CharSequence
if users really need those. For now, we are just providing the length
property, the compareTo
and the toString
functions (the plus
operations for concatenating a NotBlankString
are currently experimental). But if you need other utilities that could be added to the NotBlankString
type, feel free to suggest it.
Just another question about this topic: do you use often the CharSequence
type? I usually use the String
type for representing sequence of characters.Klitos Kyriacou
07/18/2023, 9:49 AM"...".forEach {...}
and "...".replace(regex, "...")
are both CharSequence (not String) extensions.Loïc Lamarque
07/18/2023, 10:02 AMString
type are originally extensions for the CharSequence
type.
I just don't understand the advantages of the CharSequence
abstraction. 🤔Chris Miller
07/18/2023, 8:16 PMI just don't understand the advantages of thePerformance is a big one. Creating and copying strings or substrings can be very expensive.abstraction. 🤔CharSequence
CharSequence
lets you use data directly from buffers such as java.nio.CharBuffer
and java.lang.StringBuilder
Loïc Lamarque
07/19/2023, 5:44 AMjava.lang.StringBuilder
type instead of using the kotlin.String
type?CLOVIS
07/19/2023, 9:36 AMNegativeInt
being an interface means all variables of that type must be boxed, even if it's always a StrictlyNegativeInt
which is a value class.Loïc Lamarque
07/20/2023, 12:08 AMCLOVIS
07/20/2023, 7:10 AMLoïc Lamarque
07/20/2023, 7:48 AMLoïc Lamarque
07/20/2023, 8:43 AM