0

Theres a Do method in System.Reactive to a execute a mutator for each item in the sequence.

Is there any equivalent method for IEnumerable either in standard library or third parties like morelinq?

0

1 Answer 1

1

LINQ query operators are generally meant to be free from side-effects. You could just use a foreach loop to "do" your thing.

Or do it in a Select or Where method if you don't care about side effects:

enumerable.Select(x => { /*do something here */ return x; }) 

For a List<T>, there is a ForEach extension method that can be used to execute an Action<T> for each element.

Sign up to request clarification or add additional context in comments.

2 Comments

The Do method executes the action as parte of the pipeline. ForEach does this for a materialized list, that isn't what I need. I need a pull-version of it.
I know, hence the "For a List<T>..." in the answer. So use any of my first two suggestions?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.