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
functionMatch(...params){if(thisinstanceofMatch){this.fallback=nullthis.rules=[]this.index=Match.max(0,params.indexOf(Match.pattern))}else{returnnewMatch(...params)}}Match.prototype.case=function(type,clause){if(this.fallback){throwTypeError('Match already has a default clause')}this.rules.push({type, clause})returnthis}Match.prototype.default=function(clause){if(this.fallback){throwTypeError('Match already has a default clause')}this.fallback=clausereturnthis.compile()}Match.prototype.compile=function(){if(!this.fallback){throwTypeError('Can not compile matcher that has no default case')}const{rules, index, fallback}=thisreturn(...params)=>{constpattern=params[index]for(let{type, clause}ofrules){if(type.isTypeOf(pattern)){returnclause(...params)}}returnfallback(...params)}}Match.pattern=newString('Match.pattern')Match._=newString('Match._')
Currently used patten in most code is something along these lines:
With a pattern matching it should be possible to turn it to something like this:
The text was updated successfully, but these errors were encountered: