[{"data":1,"prerenderedAt":186},["ShallowReactive",2],{"project-3360769":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":29,"sentiment":30,"stance_mix":31,"scored_comments":35,"aspects":36,"strip":41,"post_text":42,"what":43,"said":64,"maker_in_thread":114,"shape":123,"grid":128,"attempts":147,"same_week":148,"maker_shows":32,"maker_hidden":178,"reader_version":179,"card":180},"3360769","multimethod.js","a Clojure-inspired multimethod library for JavaScript","title","Show HN: multimethod.js - a Clojure-inspired multimethod library for JavaScript","http:\u002F\u002Fkrisjordan.com\u002Fmultimethod-js","krisjordan.com","KrisJordan",1324045761,2011,49,10,251,1097,23,"shown","languages","javascript library","library",[24,25,26,27,28],"multimethod","javascript","clojure","dispatch","polymorphism","curious",0.231,{"positive":32,"neutral":33,"mixed":34,"critical":34},2,3,0,5,{"design":37,"performance":39,"idea":40},{"positive":38,"critical":34},1,{"positive":34,"critical":34},{"positive":38,"critical":34},[34,35,33,34,34,33,34,33,35,34],null,{"problem":44,"audience":42,"pricing":42,"motivation":42,"time_to_build":42,"stack":56,"openness":63,"stage":63,"team_size":63},{"value":45,"source":46,"evidence":47},"Dispatching on arbitrary values, adding cases dynamically, instead of switch statements or if\u002Felse chains","commenter",[48,52],{"id":49,"by":50,"text":51},"3361762","hyperturtle","I like this very much. It's like a lightweight dispatcher\u002Frouter\u002Falternative to tons of switches\u002Fif & elses. And also that the source is very short and readable.",{"id":53,"by":54,"text":55},"3362482","swannodette","The whole point of multimethods is open extension not pattern matching. Many programming languages let you dispatch only on the first argument - the instance. multimethods…",[57],{"value":58,"source":59,"evidence":60},"JavaScript","maker",[61],{"id":62},"post","unknown",{"praise":65,"objections":77,"requests":85,"questions":97,"alternatives":102},[66,70],{"value":67,"source":46,"evidence":68},"Lightweight alternative to switches and if\u002Felse chains; source is short and readable",[69],{"id":49,"by":50,"text":51},{"value":71,"source":46,"evidence":72},"Liked the approach",[73],{"id":74,"by":75,"text":76},"3361657","cfontes","Nice stuff, I liked the approach. But what is the benchmark for this kind of structure against regular JS workflow? I guess it will be slower, but how much ?",[78],{"value":79,"source":46,"evidence":80},"Likely slower than native switch statements or prototype lookups",[81,82],{"id":74,"by":75,"text":76},{"id":83,"by":11,"text":84},"3361798","Good question. Performance will depend on a number of factors, such as how complex your dispatch function is, how complex your dispatched values and match values are (deep…",[86,90],{"value":87,"source":46,"evidence":88},"Benchmarks against regular JavaScript workflow",[89],{"id":74,"by":75,"text":76},{"value":91,"source":46,"evidence":92},"A good concrete use-case for dynamic dispatch",[93],{"id":94,"by":95,"text":96},"3362385","gerggerg","Could you comment on a good use-case for this? A time when it would actually be better to construct a switch block dynamically vs all at once.",[98],{"value":99,"source":46,"evidence":100},"How much slower is it than plain JavaScript?",[101],{"id":74,"by":75,"text":76},[103,107],{"value":104,"source":59,"evidence":105},"Switch statements and prototype chain lookups",[106],{"id":83,"by":11,"text":84},{"value":108,"source":46,"evidence":109},"patterned-function (brian-c's similar project)",[110],{"id":111,"by":112,"text":113},"3361729","brian_c","Neat! I made something (I think) similar a while back, also inspired by Clojure. Mine's more of a proof-of-concept, as I have zero Clojure experience outside some very casual…",{"comments":33,"answered":32,"key":115},[116,117,120],{"id":83,"text":84},{"id":118,"text":119},"3362045","While fib is a good example of concisely illustrating the control flow of a multimethod, it is a bad example of where it makes sense to use a multimethod. What is interesting…",{"id":121,"text":122},"3362572","Great question, probably worthy of its own post. Rather than trying to think of times you want to construct switch statements dynamically, try to think of times you'd like to…",{"commenters":124,"max_depth":125,"maker_replies":33,"first_comment_mins":126,"lifespan_hours":127},6,4,244,8,[129,131,133,135,136,139,142,144,145,146],[111,34,34,130,112,34],"commenter\u002Fneutral\u002Fidea",[49,38,35,132,50,34],"project\u002Fpositive\u002Fdesign",[74,32,33,134,75,34],"project\u002Fneutral\u002Fperformance",[83,32,34,134,11,38],[137,32,34,138,54,34],"3362496","commenter\u002Fneutral\u002Fperformance",[140,33,33,141,95,34],"3361981","project\u002Fneutral\u002Fidea",[118,33,34,143,11,38],"project\u002Fpositive\u002Fidea",[94,33,33,141,95,34],[53,33,35,143,54,34],[121,33,34,143,11,38],[],[149,154,159,164,169,174],{"id":150,"name":151,"points":152,"category":153},"3374434","Misunderstood Pigs",625,"games",{"id":155,"name":156,"points":157,"category":158},"3364942","anonysize.me",166,"consumer_social",{"id":160,"name":161,"points":162,"category":163},"3356012","Tawlk",67,"data",{"id":165,"name":166,"points":167,"category":168},"3357817","Postmates First 1000",63,"web_saas",{"id":170,"name":171,"points":172,"category":173},"3354571","my weekend+2d project",47,"infrastructure",{"id":175,"name":176,"points":177,"category":153},"3374413","My weekend project",25,false,"v2",{"id":181,"name":5,"line":6,"ai":178,"cat":20,"year":13,"points":14,"comments":15,"rec":29,"s":182,"top":18,"kw":183,"maker":11,"domain":10,"tier":19,"attempts":34,"strip":184,"url":9,"mix":185,"praise":67,"objection":79,"sub":21},3360769,0.23,[24,25,26,27,28],"0530030350",[32,33,34,34],1793990877173]