konform-kt / konform

Portable validations for Kotlin
https://www.konform.io
MIT License
651 stars 39 forks source link

Create separate extension functions for minItems and maxItems #53

Closed floatdrop closed 3 months ago

floatdrop commented 2 years ago

For now minItems and maxItems defined on T type and checks T inside. It is more concise to define them like this:

@JvmName("minItemsIterable")
fun <T, E> ValidationBuilder<out Iterable<T>, E>.minItems(
    minSize: Int
) = addConstraint(
    "must have at least {0} items",
    minSize.toString()
) { it.count() >= minSize }

@JvmName("maxItemsIterable")
fun <T, E> ValidationBuilder<out Iterable<T>, E>.maxItems(
    maxSize: Int,
) = addConstraint(
    "must have at most {0} items",
    maxSize.toString()
) { it.count() <= maxSize }
dhoepelman commented 3 months ago

I don't immediately see the advantage of this or the impact API. Will reconsider if those are listed