You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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).
... — 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).
Summary
Details
specify_any_of(),specify_one_of(), andspecify_all_of()each capture a set of specs and return a pre-configured function (of classstbl_specified_fn) that calls the correspondingstabilize_*_of(). Their implementations are nearly identical — they differ only in whichstabilize_*_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 ananyOf/oneOf/allOf).Proposed signature
Arguments
...— Unnamed stabilizer /to_*/specify_*()specs, captured and forwarded to the underlyingstabilize_*_of().Returns a function of class
c("stbl_specified_fn", "function")that calls the correspondingstabilize_*_of()with the captured specs.Behavior
specify_lst()pattern: captureelement_specs <- list(...)and return astructure(function(x, ..., x_arg, call, x_class) rlang::inject(stabilize_*_of(x, !!!element_specs, ...)), class = c("stbl_specified_fn", "function")).stabilize_any_of()(the*_one_of()→*_any_of()rename), the new exactly-onestabilize_one_of(), andstabilize_all_of()(feat: stabilize_all_of() family #278).specify_*()functions (e.g. Show actual args inspecify_*()#161).References
R/specify_lst.R,R/specify_cls.R.