Asserting/setting individual list element contents #1706
-
Are there any idiomatic and elegant ways to assert that (and set?) the Nth element of a list is a certain value? I've found 2 mechanisms thus far:
The first method seems to scale poorly the further into the list I want to assert. The 2nd has minor jankiness with the stringified indexes, and that (I /think/?) it's "assert-only", and doesn't "push" elements back to the original list, if they were unset. What's the current state of the art in this area? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
I would do something like this: import "list"
l: 10
// Establsh a list of length l
x: [for i in list.Range(0, l, 1) { _ }]
// Assert that the element at index 5 is 4
x: [for i in list.Range(0, l, 1) { if i == 5 { 4 } }] |
Beta Was this translation helpful? Give feedback.
-
With the query extension (#165), we intend to allow something like:
or even
|
Beta Was this translation helpful? Give feedback.
I would do something like this:
Playground link