Serializable predicates for Scala 3
Find a file
Pat Garrity 48c773f449
All checks were successful
/ Build and Release Library (push) Successful in 2m28s
(patch) Adding builds and minor documentation. (#2)
Reviewed-on: #2
2025-11-27 20:41:42 +00:00
.forgejo/workflows (patch) Adding builds and minor documentation. (#2) 2025-11-27 20:41:42 +00:00
docs json module functions properly and is documented 2025-11-14 22:12:47 -06:00
project json module functions properly and is documented 2025-11-14 22:12:47 -06:00
src (patch) Adding builds and minor documentation. (#2) 2025-11-27 20:41:42 +00:00
.gitignore Initialize the repository with a baseline predicate implementation and minimal tests. 2025-11-03 09:00:35 -06:00
.pre-commit-config.yaml Initialize the repository with a baseline predicate implementation and minimal tests. 2025-11-03 09:00:35 -06:00
.scalafmt.conf (patch) Adding builds and minor documentation. (#2) 2025-11-27 20:41:42 +00:00
build.sbt refactored entire library 2025-11-26 22:46:06 -06:00
LICENSE Initialize the repository with a baseline predicate implementation and minimal tests. 2025-11-03 09:00:35 -06:00
README.md (patch) Adding builds and minor documentation. (#2) 2025-11-27 20:41:42 +00:00

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 bar such that any one element of bar...
  • Contains an array baz such that all elements of baz...
  • Are objects that contain some property xyz with 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

  • true
  • false
  • and
  • or
  • string comparison
  • json comparison

List of Comparison Operations

  • true
  • false
  • and
  • or
  • eq
  • neq

For Strings

  • contains
  • prefix
  • suffix

When Parsed as Integer

  • <
  • <=
  • >
  • >=
  • Inclusive Range
  • Exclusive Range

When Parsed as Date

  • before
  • after
  • Inclusive Range
  • Exclusive Range

Donate

Enjoy this project or want to help me achieve my goals? Consider Donating to Pat on Ko-fi.