Skip to content

Commit b7af177

Browse files
authored
✨ feat(constraints): add configSizeOrNull function for collection siz… (#361)
2 parents 33f998f + ff4d25b commit b7af177

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package dev.slne.surf.api.core.config.constraints
2+
3+
import dev.slne.surf.api.core.config.type.StringOrDefault
4+
5+
internal tailrec fun Any?.configSizeOrNull(): Int? = when (this) {
6+
null -> null
7+
is Collection<*> -> size
8+
is Map<*, *> -> size
9+
is Array<*> -> size
10+
is CharSequence -> length
11+
is StringOrDefault -> value?.configSizeOrNull()
12+
else -> null
13+
}

0 commit comments

Comments
 (0)