littlebits / stream-sift

A minimal high-performance specification-backed stateful object matching engine
MIT License
1 stars 1 forks source link

$maybe #13

Open jasonkuhrt opened 9 years ago

jasonkuhrt commented 9 years ago

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".