Does for_each guarantee the order?

Hi everyone, I want to use for_each to walk through my array, but I wonder if it guarantee the order or not? I checked the Document but I didn’t find any information.
Thank you in advance

Order as in positional order within the array ? If so yes.

Depends, if the data structure specofies an order, then yes for_each will walk the data structure in order. So, yes arrays will be walked in prder. But if the data structure does not guarantee an order, then no. For example, a HashSet will be walked in an unspecified order. But in either case, every element will be produced. (Unless other iterator adaptors are used, like filter or take)

1 Like