Serializable predicates for Scala 3
|
All checks were successful
/ Build and Release Library (push) Successful in 2m31s
Reviewed-on: #3 |
||
|---|---|---|
| .forgejo/workflows | ||
| docs | ||
| project | ||
| src | ||
| .gitignore | ||
| .pre-commit-config.yaml | ||
| .scalafmt.conf | ||
| build.sbt | ||
| LICENSE | ||
| README.md | ||
gs-predicate
GS Open Source | License (MIT)
Serializable predicates for Scala 3. Circe is used for JSON representations.
Usage
Dependency
This artifact is available in the Garrity Software Maven repository.
externalResolvers +=
"Garrity Software Releases" at "https://maven.garrity.co/gs"
val GsPredicate: ModuleID =
"gs" %% "gs-predicate-api-v0" % "$VERSION"
JSON Predicates
The following example evaluates whether some JSON object:
- Contains an object
foo... - That contains an array
barsuch that any one element ofbar... - Contains an array
bazsuch that all elements ofbaz... - Are objects that contain some property
xyzwith value"example".
import io.circe.Json
import gs.predicate.v0.api.*
import gs.predicate.v0.json.*
import gs.predicate.v0.json.query.JsonQuery
val predicate = JsonComparisonPredicate(
JsonQuery.compile("foo.bar[any].baz[all].xyz"),
JsonComparison.Eq(Json.fromString("example"))
)
val json = io.circe.parser.parse("""
{
"foo": {
"bar": [
{
"baz": [
{ "xyz": "example" },
{ "xyz": "example" }
]
},
{
"baz": [
{ "xyz": "oops" },
{ "xyz": "example" }
]
}
]
}
}
""".stripMargin)
assertEquals(predicate.eval(json), Predicate.Result.matched())
List of Predicates
truefalseandor- string comparison
- json comparison
List of Comparison Operations
truefalseandoreqneq
For Strings
containsprefixsuffix
When Parsed as Integer
<<=>>=- Inclusive Range
- Exclusive Range
When Parsed as Date
beforeafter- Inclusive Range
- Exclusive Range
Donate
Enjoy this project or want to help me achieve my goals? Consider Donating to Pat on Ko-fi.