One-item sequences should not resolve to array
See original GitHub issueI think it would simplify a lot grammars if sequences with a single element would be unboxed automatically.
expression -> boolean | null
boolean -> "true" | "false"
null -> "null"
Matching for “true” currently returns [ [ "true" ] ]
, with unboxing, it would simply return "true"
.
Currently, to achieve the same result, I have to use a lot of id
s (especially combined with alternatives):
expression -> boolean {% id %} | null {% id %}
boolean -> "true" {% id %} | "false" {% id %}
null -> "null" {% id %}
Issue Analytics
- State:
- Created 7 years ago
- Comments:10 (8 by maintainers)
Top Results From Across the Web
How to synchronize a sequence of promises? - Stack Overflow
The initial answers suggest we can only sequence results of such array elements, not their execution, because it is predefined in such example....
Read more >$filter does not return an array if no or only one item matches
As with the path syntax, the empty filter operator [] should be used to keep singleton sequences as arrays, e.g. $filter($, function($e) {...
Read more >Solved Double Array Sequences java Hey I'm having a - Chegg
empty, the method should return <>. If the sequence has one item, say 1.1, and that item is not the current item, the...
Read more >Seq (FSharp.Core)
This function digests the whole initial sequence as soon as it is called. As a result this function should not be used with...
Read more >Collections - gigamonkeys
With no other arguments, MAKE-ARRAY will create a vector with uninitialized ... ELT , short for element, takes a sequence and an integer...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I don’t think it really impacts consistency: a single item is not seen as a sequence by users.
But I understand the compatibility issue, I though about it, but I think this change would really improve the usability of nearley, maybe it could ship in the next major version?
Yes, that looks cleaner, I agree. What about
statement -> foo | bar qux
? Isfoo
an array or not? What aboutstatement -> foo | bar
?Personally, I find it easier to work with current consistent model. It doesn’t force me to think as much, and I can focus on higher-level stuff.
P.S. In ES6+ use parameter destructuring:
([ part ]) => { type: 'Statement', value: part }