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
I was struggling to understand how this library works. Your example does not provide the sample data the matches are compared against. Reading the test code helped, but maybe you can start with a less complicated example. Here is an example that helped me understand better:
varmatch=require("pattern-match")letmyobj={a: 1,b: 2}// Just check if object properties exist and do somethingmatch(myobj,(when)=>{when({c:match.any},()=>{console.log('object with "c" property detected')});when({a:match.any},()=>{console.log('object with "a" property detected')});// This will never be reached since the previous check matchedwhen({a:match.any,b: match.any},()=>{console.log('object with "a" and "b" properties detected')});});// capture the property values with new namesmatch(myobj,(when)=>{when({a:match.var('foo'),b: match.var('bar')},(submatch)=>{console.log('Sub-Match object is',submatch)});});
The text was updated successfully, but these errors were encountered:
I was struggling to understand how this library works. Your example does not provide the sample data the matches are compared against. Reading the test code helped, but maybe you can start with a less complicated example. Here is an example that helped me understand better:
The text was updated successfully, but these errors were encountered: