Path: csiph.com!news.swapon.de!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Ben Bacarisse Newsgroups: comp.lang.javascript Subject: Re: passing a set of numbers to a function Date: Fri, 05 Feb 2016 14:34:49 +0000 Organization: A noiseless patient Spider Lines: 21 Message-ID: <87twlnkyye.fsf@bsb.me.uk> References: <19679ed0-c594-4f7e-817c-a72bd5c10411@googlegroups.com> <22041181.SJtjrm8m6U@PointedEars.de> <87r3gso59h.fsf@bsb.me.uk> <1603158.xI32ru06Pi@PointedEars.de> <58b65993-5943-4f8e-a4e2-9e97bb1feea3@googlegroups.com> <7de86700-d479-49ff-819f-8187843a09b8@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: mx02.eternal-september.org; posting-host="017616aa25f81ec581c44d76d61ba2f3"; logging-data="20814"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+/GlAh2MXL9s5cQo4fyKy0zJ/jfEUEW2o=" Cancel-Lock: sha1:ZVDzXyu+s8Tc2wUTk5jqwJkJAL0= sha1:GJc8rdrWBPDodMww00R16Znidew= X-BSB-Auth: 1.5645da82fbbd4b7a1d09.20160205143449GMT.87twlnkyye.fsf@bsb.me.uk Xref: csiph.com comp.lang.javascript:29541 Scott Sauyet writes: > I wasn't thinking about practical implementation at all. > But they're an interesting exercise regardless. I think there are practical uses. I've used this method on a web site (hey, topical!) that had complex match expressions in a search function. To implement something like ("a" | "b") & ~"c" you parse the expression and build a matching functions as you go. Given something like function any(x) { return set(s => s.includes(x)); } the result of parsing ("a" | "b") & ~"c" is const r = (any("a").union(any("b")).intersection(any("c").complement())); and you simply test r.contains("whatever") to do the match. -- Ben.