4 ms·
> Thinking || allows for set operations: states.includes('VALID' || 'IN_PROGRESS') Genuinely wondering what language that would have been valid in.
by twisteriffic 3y ago
> Thinking || allows for set operations: states.includes('VALID' || 'IN_PROGRESS')
Genuinely wondering what language that would have been valid in.
- malfist 3y agoEnglish. Have a brain fart one day and you'll write something like this and be confused why it doesn't work
- swatcoder 3y agoThe type system in TypeScript can compose types from string literals using a similar syntax. Obviously, this is runtime code, not a type declaration, but you can see how a new or tired/busy developer’s brain might spit this out in the wrong place.
- recursive 3y agoYou can do this in C#, which is similar if you squint. states.Any(s => s is "VALID" or "IN_PROGRESS") I'm sure there are languages where a match-able pattern is an expression, allowing the original code basically unchanged.
- simlevesque 3y agoYou can do it in JS too: states.find(state => state === 'VALID' || state === 'IN_PROGRESS') Or states.find(state => ['VALID', 'IN_PROGRESS'].includes(state))
- recursive 3y agoThis is a little further away IMO, as it doesn't have the `v1 or v2` construction.
- dragonwriter 3y ago> Genuinely wondering what language that would have been valid in. Raku, but using “junctive or” | (which creates an any junction of its arguments, which “autothreads” on method calls producing a Junction of the results) instead of “tight or” ||.
- nodoodles 3y agoOne could abuse Kotlin to make almost this syntax valid. Something like: states.includes { +”VALID” || +”IN_PROGRESS” } Where statestype function ‘includes’ takes a lambda that’s run in states context and overrides plus operator for string to evaluate to states.contains(that string). One could, but should they?
- SonOfLilit 3y agoI was amazed to discover COBOL has something like this: IF X = 0 OR = 1 OR = 2
- barosl 3y ago> states.intersection({'VALID'} | {'IN_PROGRESS'}) Does this Python code count? Haha.
- masklinn 3y agoNo, that’s the explicit conjunction of two explicit sets. ‘VALID’ or ‘IN_PROGRESS’ in states Does not work and I’ve seen it around or SO. Or more commonly it’s variation a == b or c
- lizmat 3y agoAlmost in the Raku Programming Language, bit with a single | states.includes('VALID' | 'IN_PROGRESS') is effectively the same as: states.includes('VALID') || states.includes('IN_PROGRESS') See https://docs.raku.org/type/Junction https://docs.raku.org/type/Junction
- baq 3y agodatadog allows exactly this syntax modulo JS: attribute:(value OR another_value)
- deleted 3y ago[deleted]