[{"data":1,"prerenderedAt":234},["ShallowReactive",2],{"project-4516576":3},{"id":4,"name":5,"line":6,"line_source":7,"title":8,"url":9,"domain":10,"maker":11,"posted_at":12,"year":13,"points":14,"comments":15,"rank_in_year":16,"shown_in_year":17,"top":18,"tier":19,"category":20,"subcategory":21,"format":22,"keywords":23,"reception":28,"sentiment":29,"stance_mix":30,"scored_comments":35,"aspects":36,"strip":40,"post_text":42,"what":43,"said":66,"maker_in_thread":140,"shape":151,"grid":154,"attempts":197,"same_week":198,"maker_shows":33,"maker_hidden":226,"reader_version":227,"card":228},"4516576","Matches.js","Powerful Pattern Matching for Javascript","title","Show HN: Matches.js -- Powerful Pattern Matching for Javascript","https:\u002F\u002Fgithub.com\u002Fnatefaubion\u002Fmatches.js","github.com","natefaubion",1347549564,2012,96,20,228,1677,14,"notable","languages","javascript library","library",[24,25,26,27],"pattern matching","javascript","function overloading","dispatch","mixed",0.238,{"positive":31,"neutral":32,"mixed":33,"critical":34},4,3,1,2,10,{"idea":37,"design":39},{"positive":32,"critical":38},0,{"positive":33,"critical":34},[32,38,32,41,32,38,41,32,38,33,38,33,38,38,38,38,38,38,41,41],5,null,{"problem":44,"audience":42,"pricing":42,"motivation":42,"time_to_build":42,"stack":56,"openness":65,"stage":65,"team_size":65},{"value":45,"source":46,"evidence":47},"Replacing conditional branching with declarative pattern-based dispatch","commenter",[48,52],{"id":49,"by":50,"text":51},"4517393","OmarIsmail","I didn't know I needed this until I saw it and had that A-HA moment when I realized how much cleaner this would make a lot of code. Instead of hiding away the logic in a bunch of…",{"id":53,"by":54,"text":55},"4517112","tlack","You know how a lot of jQuery functions take either a string, or a function, or an array of strings, etc? Instead of making those decisions in your code in a series of IF…",[57],{"value":58,"source":59,"evidence":60},"JavaScript","inferred",[61],{"id":62,"by":63,"text":64},"4517730","jpolitz","Cool! Sucks that it has to be so stringly typed, but I can't see another alternative. One concern: \"Each pattern will be tried in order until a match is found.\" As far as I know,…","unknown",{"praise":67,"objections":83,"requests":102,"questions":110,"alternatives":118},[68,72],{"value":69,"source":46,"evidence":70},"Makes overloading declarative and cleaner for maintenance",[71],{"id":49,"by":50,"text":51},{"value":73,"source":46,"evidence":74},"Useful addition to JavaScript",[75,79],{"id":76,"by":77,"text":78},"4517259","elliotlai","i want this in js for a long time",{"id":80,"by":81,"text":82},"4519548","dreamdu5t","Awesome! This is so useful!",[84,88,98],{"value":85,"source":46,"evidence":86},"Relies on object key order, which ECMAScript does not guarantee",[87],{"id":62,"by":63,"text":64},{"value":89,"source":46,"evidence":90},"Readability concerns in large JavaScript codebases",[91,95],{"id":92,"by":93,"text":94},"4517391","se85","I've come across aspects of this functionality before in a couple of languages now, even psql, however looking at this JavaScript way of doing it, I have to question whether it…",{"id":96,"by":93,"text":97},"4517488","Thanks, I misread the first time, made sense the second time! My mistake! I still have my doubts as to how readable such an approach like this would be in large JavaScript…",{"value":99,"source":46,"evidence":100},"String-based patterns feel stringly typed",[101],{"id":62,"by":63,"text":64},[103],{"value":104,"source":46,"evidence":105},"Support for CoffeeScript-style pattern matching",[106],{"id":107,"by":108,"text":109},"4518110","danh","Something like this would make a great addition to CoffeeScript.",[111],{"value":112,"source":46,"evidence":113},"What are applications of pattern matching?",[114],{"id":115,"by":116,"text":117},"4516648","username3","What are some applications of pattern matching?",[119,126,133],{"value":120,"source":46,"evidence":121},"Multimethods via bilby.js",[122],{"id":123,"by":124,"text":125},"4519367","pufuwozu","Sucks that it has to be so stringly typed, but I can't see another alternative. Multimethods would be an alternative to this type of ad-hoc polymorphism. I've encoded immutable…",{"value":127,"source":46,"evidence":128},"LiveScript implicit switch",[129],{"id":130,"by":131,"text":132},"4518564","oscilloscope","Check out LiveScript's implicit switch syntax: http:\u002F\u002Fgkz.github.com\u002FLiveScript\u002F#switch",{"value":134,"source":46,"evidence":135},"XRegExp",[136],{"id":137,"by":138,"text":139},"4519230","pooriaazimi","For those interested: XRegExp (http:\u002F\u002Fxregexp.com) is also relevant. (Not a direct competitor to Matches.js, but has some nice features)",{"comments":41,"answered":33,"key":141},[142,145,148],{"id":143,"text":144},"4517804","You are correct. There is not a guarantee for the future, though I doubt this behavior will change for V8 (this is currently node only). If that scares you, you can use the…",{"id":146,"text":147},"4516716","Pattern matching is common in functional languages like Haskell or Scala. It's like a form of overloading on steroids, letting you inspect the values and structure of the…",{"id":149,"text":150},"4517437","Take a look at the next sentence: \"Keep in mind, that time is measured in the single microseconds (1µs vs 3µs) to dispatch 5 calls to the same function.\" So you are still looking…",{"commenters":152,"max_depth":31,"maker_replies":41,"first_comment_mins":153,"lifespan_hours":35},15,12,[155,157,159,161,163,164,165,167,170,174,176,178,179,180,183,186,187,189,193,195],[62,38,32,156,63,38],"project\u002Fmixed\u002Fidea",[143,38,38,158,11,33],"maker\u002Fneutral\u002Fexecution",[123,38,32,160,124,38],"project\u002Fneutral\u002Fidea",[49,33,41,162,50,38],"project\u002Fpositive\u002Fdesign",[115,34,32,160,116,38],[146,34,38,160,11,33],[53,34,41,166,54,38],"project\u002Fpositive\u002Fidea",[168,34,32,160,169,38],"4517873","agumonkey",[171,32,38,172,173,38],"4517979","other\u002Fneutral\u002Fnone","ntoshev",[92,31,33,175,93,38],"project\u002Fcritical\u002Fdesign",[149,31,38,177,11,33],"maker\u002Fneutral\u002Fperformance",[96,31,33,175,93,38],[137,41,38,172,138,38],[107,181,38,182,108,38],6,"other\u002Fpositive\u002Fidea",[184,181,38,185,11,33],"4518175","project\u002Fmixed\u002Fdesign",[130,181,38,172,131,38],[188,181,38,172,11,33],"4518646",[190,181,38,191,192,38],"4519586","other\u002Fneutral\u002Fidea","ble",[76,194,41,166,77,38],7,[80,196,41,166,81,38],8,[],[199,204,208,213,218,222],{"id":200,"name":201,"points":202,"category":203},"4538949","EasyPost",157,"web_saas",{"id":205,"name":206,"points":207,"category":203},"4517611","ScrollKit",131,{"id":209,"name":210,"points":211,"category":212},"4532754","Roll20",74,"games",{"id":214,"name":215,"points":216,"category":217},"4545078","Screenleap",59,"dev_tools",{"id":219,"name":220,"points":221,"category":203},"4540076","HN Tees",53,{"id":223,"name":224,"points":225,"category":217},"4539910","instafilter.io",47,false,"v2",{"id":229,"name":5,"line":6,"ai":226,"cat":20,"year":13,"points":14,"comments":15,"rec":28,"s":230,"top":18,"kw":231,"maker":11,"domain":10,"tier":19,"attempts":38,"strip":232,"url":9,"mix":233,"praise":69,"objection":85,"sub":21},4516576,0.24,[24,25,26,27],"30353053010100000055",[31,32,33,34],1794036499459]