Skip to content

feat: specify_any_of(), specify_one_of(), and specify_all_of() #288

Description

@jonthegeek

Summary

As a package developer, in order to build reusable, pre-configured composition validators, I would like specify_*() factories for the any_of, one_of, and all_of families.

Details

specify_any_of(), specify_one_of(), and specify_all_of() each capture a set of specs and return a pre-configured function (of class stbl_specified_fn) that calls the corresponding stabilize_*_of(). Their implementations are nearly identical — they differ only in which stabilize_*_of() they wrap — so they are grouped into one issue.

These factories are what make composition composable: e.g. stabilize_each(x, specify_any_of(specify_int(), specify_chr())), and they map directly onto nested JSON Schema composition (an object property whose schema is itself an anyOf / oneOf / allOf).

Proposed signature

specify_any_of(...)
specify_one_of(...)
specify_all_of(...)

Arguments

  • ... — Unnamed stabilizer / to_* / specify_*() specs, captured and forwarded to the underlying stabilize_*_of().

Returns a function of class c("stbl_specified_fn", "function") that calls the corresponding stabilize_*_of() with the captured specs.

Behavior

  • Follow the existing specify_lst() pattern: capture element_specs <- list(...) and return a structure(function(x, ..., x_arg, call, x_class) rlang::inject(stabilize_*_of(x, !!!element_specs, ...)), class = c("stbl_specified_fn", "function")).
  • Depends on the three underlying functions: stabilize_any_of() (the *_one_of()*_any_of() rename), the new exactly-one stabilize_one_of(), and stabilize_all_of() (feat: stabilize_all_of() family #278).
  • Keep behavior/argument-echoing consistent with the other specify_*() functions (e.g. Show actual args in specify_*() #161).

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    JSON schemanecessary for JSON schema supportai-created 🤖📝written by AI; requires vetting by a human; remove this label after reviewingmeta-stabilizers`stabilize_any_of()` etc

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions