Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

One-item sequences should not resolve to array

See original GitHub issue

I 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 ids (especially combined with alternatives):

expression -> boolean {% id %} | null {% id %}
boolean -> "true" {% id %} | "false" {% id %}
null -> "null" {% id %}

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:10 (8 by maintainers)

github_iconTop GitHub Comments

julien-fcommented, Mar 20, 2017

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?

deltaideacommented, Jul 14, 2017

Yes, that looks cleaner, I agree. What about statement -> foo | bar qux? Is foo an array or not? What about statement -> 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 }

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found