Open atifaziz opened 7 years ago
This sounds a lot like #81, which was rejected.
@fsateler #81 was not rejected. It was closed because Craig said “Nevermind then“ when I pointed out that Index
can be used to the same effect. If anything, I'd say #236 is identical to #81. This one, however, is about multiple searches and finding the first occurrence of each.
I propose to add a new operator that takes some sequence of elements and a set of predicates, and returns a sequence of the first matching element (along with its index) for each predicate. The returned matches will be in the order of the predicates. If a predicate has no satisfying element, then its corresponding result will be an index of -1 and undefined element. The search terminates as soon as all predicates have at least one matching element or the source is exhausted. An overload can be supplied on top of this to simply provide values sought (optionally with an equality comparer) instead of predicates.
The source sequence is iterated once. A predicate is evaluated once per element and it is only used as long no matching element has satisfied it.
Prototype
Example