question-mark
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.

Allow length to work on optional arrays

See original GitHub issue

Right now:

  input {
    Array[Int] xs = [1, 2, 3]
    Array[Int]? ys = [1, 2, 3]
    Array[Int]? zs # Imagine this doesn't get supplied
  }

  Int len_xs = length(xs) # Returns 3
  Int len_ys = length(ys) # Doesn't work
  Int len_zs = length(zs) # Doesn't work

It seems sensible to me to also allow behavior like:

  input {
    Array[Int] xs = [1, 2, 3]
    Array[Int]? ys = [1, 2, 3]
    Array[Int]? zs # Imagine this doesn't get supplied
  }

  Int len_xs = length(xs) # Returns 3
  Int len_ys = length(ys) # Returns 3
  Int len_zs = length(zs) # Returns 0

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:10 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
yfarjouncommented, Aug 3, 2018

right…so

select_first([ maybeArray, []])

will either return maybeArray (if present) or [] (if not) after which you can run length and get 0 when array is not present.

0reactions
patmageecommented, Nov 20, 2019

closing this as it seems the agreed upon solution in the current spec is:

select_first([ maybeArray, []])
Read more comments on GitHub >

github_iconTop Results From Across the Web

Fixed array length with an optional item - typescript
One of my function parameters should always accept a homogeneous array of 1 or 2 elements, something like this:
Read more >
Why were variable length arrays made optional in C 2011?
I've heard legends varying from "it should be optional as some small compilers should be able to be C11-compliant without VLAs" to "it...
Read more >
Values and Types - Cadence - Flow Developers
Values are objects, like for example booleans, integers, or arrays. ... See the optional operators section for information on how to work with...
Read more >
5 ways to check if a Javascript Array is empty - Level Up Coding
Is JS array empty? Does it exist? · 1. The length property · 2. And (&&) operator and length · 3. Optional chaining...
Read more >
Indexed collections - JavaScript - MDN Web Docs - Mozilla
However, you can use the predefined Array object and its methods to work with arrays ... for (let i = 0; i <...
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 Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found