Add isNotEmpty, isNotBlank methods (#1396)

Adds convenience methods `isNotEmpty` and `isNotBlank`. This borrows the
same methods from Kotlin.

This helps users write more fluent constraints, for example,
`foo.isNotEmpty.implies(bar)`.

Adds:

* List#isNotEmpty
* Map#isNotEmpty
* Set#isNotEmpty
* Mapping#isNotEmpty
* Listing#isNotEmpty
* String#isNotEmpty
* String#isNotBlank
This commit is contained in:
Daniel Chao
2026-01-08 13:22:43 -08:00
committed by GitHub
parent 14d58a17b0
commit ac4f2fd9a6
23 changed files with 1133 additions and 19 deletions
@@ -12,6 +12,11 @@ facts {
!list1.isEmpty
}
["isNotEmpty"] {
!List().isNotEmpty
list1.isNotEmpty
}
["every()"] {
list1.every((x) -> x <= 3)
!list1.every((x) -> x > 2)
@@ -42,7 +42,16 @@ facts {
!altered.isEmpty
!computedIndex.isEmpty
}
["isNotEmpty"] {
!empty.isNotEmpty
!empty2.isNotEmpty
base.isNotEmpty
derived.isNotEmpty
altered.isNotEmpty
computedIndex.isNotEmpty
}
["lastIndex"] {
empty.lastIndex == -1
empty2.lastIndex == -1
@@ -8,6 +8,11 @@ facts {
!map1.isEmpty
}
["isNotEmpty"] {
!Map().isNotEmpty
map1.isNotEmpty
}
["containsKey()"] {
map1.containsKey("two")
!Map().containsKey("two")
@@ -48,6 +48,13 @@ facts {
empty2.isEmpty
}
["isNotEmpty"] {
base.isNotEmpty
derived.isNotEmpty
!empty.isNotEmpty
!empty2.isNotEmpty
}
["containsKey()"] {
base.containsKey("Pigeon")
base.containsKey("Parrot")
@@ -12,6 +12,11 @@ facts {
!set1.isEmpty
}
["isNotEmpty"] {
!Set().isNotEmpty
set1.isNotEmpty
}
["every()"] {
set1.every((x) -> x <= 3)
!set1.every((x) -> x > 2)
@@ -11,6 +11,11 @@ facts {
!str1.isEmpty
}
["isNotEmpty"] {
!"".isNotEmpty
str1.isNotEmpty
}
["isBlank"] {
"".isBlank
" ".isBlank
@@ -18,6 +23,13 @@ facts {
!str1.isBlank
}
["isNotBlank"] {
!"".isNotBlank
!" ".isNotBlank
!"\t\n\r".isNotBlank
str1.isNotBlank
}
["isBase64"] {
"".isBase64
"AQIDBA==".isBase64
@@ -3,6 +3,10 @@ facts {
true
true
}
["isNotEmpty"] {
true
true
}
["every()"] {
true
true
@@ -7,6 +7,14 @@ facts {
true
true
}
["isNotEmpty"] {
true
true
true
true
true
true
}
["lastIndex"] {
true
true
@@ -3,6 +3,10 @@ facts {
true
true
}
["isNotEmpty"] {
true
true
}
["containsKey()"] {
true
true
@@ -5,6 +5,12 @@ facts {
true
true
}
["isNotEmpty"] {
true
true
true
true
}
["containsKey()"] {
true
true
@@ -830,6 +830,30 @@ alias {
name = "isEmpty"
allModifiers = Set()
allAnnotations = List()
}, "isNotEmpty", new {
location {
line = XXXX
column = 3
displayUri = "https://github.com/apple/pkl/blob/$commitId/stdlib/base.pkl#LXXXX"
}
docComment = """
Tells whether this string is not empty.
Facts:
```
!"".isNotEmpty
"abc".isNotEmpty
```
"""
annotations = List(new {
version = "0.31.0"
})
modifiers = Set()
name = "isNotEmpty"
allModifiers = Set()
allAnnotations = List(new {
version = "0.31.0"
})
}, "isBlank", new {
location {
line = XXXX
@@ -852,6 +876,32 @@ alias {
name = "isBlank"
allModifiers = Set()
allAnnotations = List()
}, "isNotBlank", new {
location {
line = XXXX
column = 3
displayUri = "https://github.com/apple/pkl/blob/$commitId/stdlib/base.pkl#LXXXX"
}
docComment = """
Tells if at least one character is not Unicode "White_Space".
Facts:
```
!"".isNotBlank
!" ".isNotBlank
"\\t\\n\\r".isNotBlank
"abc".isNotBlank
```
"""
annotations = List(new {
version = "0.31.0"
})
modifiers = Set()
name = "isNotBlank"
allModifiers = Set()
allAnnotations = List(new {
version = "0.31.0"
})
}, "isRegex", new {
location {
line = XXXX
@@ -1124,6 +1174,30 @@ alias {
name = "isEmpty"
allModifiers = Set()
allAnnotations = List()
}, "isNotEmpty", new {
location {
line = XXXX
column = 3
displayUri = "https://github.com/apple/pkl/blob/$commitId/stdlib/base.pkl#LXXXX"
}
docComment = """
Tells whether this string is not empty.
Facts:
```
!"".isNotEmpty
"abc".isNotEmpty
```
"""
annotations = List(new {
version = "0.31.0"
})
modifiers = Set()
name = "isNotEmpty"
allModifiers = Set()
allAnnotations = List(new {
version = "0.31.0"
})
}, "isBlank", new {
location {
line = XXXX
@@ -1146,6 +1220,32 @@ alias {
name = "isBlank"
allModifiers = Set()
allAnnotations = List()
}, "isNotBlank", new {
location {
line = XXXX
column = 3
displayUri = "https://github.com/apple/pkl/blob/$commitId/stdlib/base.pkl#LXXXX"
}
docComment = """
Tells if at least one character is not Unicode "White_Space".
Facts:
```
!"".isNotBlank
!" ".isNotBlank
"\\t\\n\\r".isNotBlank
"abc".isNotBlank
```
"""
annotations = List(new {
version = "0.31.0"
})
modifiers = Set()
name = "isNotBlank"
allModifiers = Set()
allAnnotations = List(new {
version = "0.31.0"
})
}, "isRegex", new {
location {
line = XXXX
@@ -3,6 +3,10 @@ facts {
true
true
}
["isNotEmpty"] {
true
true
}
["every()"] {
true
true
@@ -3,12 +3,22 @@ facts {
true
true
}
["isNotEmpty"] {
true
true
}
["isBlank"] {
true
true
true
true
}
["isNotBlank"] {
true
true
true
true
}
["isBase64"] {
true
true