This may be a bad idea because it could lead to sloppy pattern matching but worth considering. The $maybe function would match its containing pattern against any data _that has the key of $maybe_. Consider:
{ foo: { bar: { $maybe: { a: 1 } } } }
That would match { foo: { bar: { a: 1 } } } or { foo: { blah: 'zed' } } but not{ foo: { bar: { a: 3 } } }.
So the $maybe function states "if my key exists it must match this pattern".
This may be a bad idea because it could lead to sloppy pattern matching but worth considering. The
$maybe
function would match its containing pattern against any data _that has the key of$maybe
_. Consider:That would match
{ foo: { bar: { a: 1 } } }
or{ foo: { blah: 'zed' } }
but not{ foo: { bar: { a: 3 } } }
.So the
$maybe
function states "if my key exists it must match this pattern".