Proposal - Preserve #32
TotalTechGeek
started this conversation in
Ideas
Replies: 1 comment
-
Self +1 Current Votes
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Background
Apologies for the deluge of simultaneous proposals.
As it looks like: https://github.com/orgs/json-logic/discussions/28 has succeeded, I'm going to propose one more operator for "Core".
After this, I think I'm going to personally try to avoid adding additional operators to JSON Logic Core, although there is a case to be made for a few simple string operators like
startsWIth
andendsWith
... Though those could become a community extension rather than a Core operator.Anyway, getting to the point:
Some folks have found it useful to be able to embed data in their logic.
json-logic-js
had a quirk where if an object had >1 keys, it would be treated as embedded data, though this wasn't standard across most implementations of JSON Logic. However, this prevented you from returning objects with a single key, unless it was embedded in context.In
json-logic-engine
, this is handled with apreserve
operator, which intentionally preserves the argument and performs no transformation work on it.Proposal
I'd like to suggest we add a
preserve
operator, which is a lazy operator which simply returns its argument without any evaluation or processing.Put another way,
preserve
is a lazy operator that simply executes the identity function on its argument.This operator makes it simple to embed data (specifically objects or arrays) in the AST, without it being executed.
Tests
preserve
Beta Was this translation helpful? Give feedback.
All reactions