Forum Discussion
List.Select does not work as expected when List contains Errors
- 8 years ago
The reason for this behavior is that lists in M are lazy. The previews (in the Query Editor) of both the "each false" and "each true" queries actually produce the same result. In both cases, the Query Editor attempts to show all the values, which causes List.Select to traverse its entire source list. In the process, it encounters the error value, which interrupts its enumeration of the source list, resulting in a list that contains an error.
However, when you navigate into the first item in the resulting list, both the "each false" and "each true" queries attempt to get only the first item resulting from the List.Select. Since the "each true" query's List.Select condition will "match" any input, the “Hello” value is selected and returned, and the error value is never encountered. However, in the "each false" query, the first two inputs do not "match", and thus it moves on to the error value, which interrupts its enumeration and causes the error to bubble up.
Hope this helps clarify things.
Ehren
Good question. When you navigate into the first element in the "each true" query, try replacing the generated list index of {0} with {1}, and you should see the second value in the list.
The error doesn't just cause the enumeration of the list to stop...it actually changes the result of enumeration to an error.
Ehren