Share via

Why I get an error in this code?

Andrey Minakov 1 Reputation point
2020-12-07T17:56:33.217+00:00

Why I have an error here?

List.First(List.Accumulate({1, 2 / "f"}, {}, (v,i)=> v & {i}))

PQ is lazy and provides streaming semantics for lists, and the source for List.First (1) is a list (List.Accumulate... (2)). So,
A) due to streaming semantics, if 1 gets the first element of 2, execution of 2 should stop;
B) due to laziness, the calculation of the second list element of 2 shouldn't happen before any call for it.

So we should not get the error here...

And in this case, all is OK:

List.First(List.Select({1, 2 / "f"}, each _ > 0))

And I'm sure that in the case of List.Generate all will be OK either.

Community Center | Not monitored
0 comments No comments

1 answer

Sort by: Most helpful
  1. Ehren (MSFT) 1,786 Reputation points Microsoft Employee
    2021-01-20T00:02:28.403+00:00

    List.Accumulate iterates over the items in the list to compute its result (which in your case happens to be a list). It's this inner iteration that is throwing the error, not the iteration done by List.First.

    Ehren

    Was this answer helpful?

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.