Allow length to work on optional arrays
See original GitHub issueRight 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:
- Created 5 years ago
- Comments:10 (9 by maintainers)
Top 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 >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
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.
closing this as it seems the agreed upon solution in the current spec is: