Optional icon indicating copy to clipboard operation
Optional copied to clipboard

Map Exception and inner value

Open Clindbergh opened this issue 2 years ago • 2 comments

In the following code

IEnumerable<(A, Option<B, Exception>)> result = aValues
                .Select(a => (a, a.ComputeB())

I wish to transform the value (A, Option<B, Exception>) to Option<(A, B), (A, Exception)>.

For this operation a Map operation that transforms both, the inner value or the exception value is missing. It is only possible to specify one mapper instead of a mapper for both cases.

Clindbergh avatar Nov 29 '21 19:11 Clindbergh

Any reason a chained .Map(...).MapException(...) wouldn't do? My initial thought is that it seems a bit too much of an edge case to have a dedicated method for the purpose.

nlkl avatar Nov 29 '21 19:11 nlkl

Actually, that would work. I wonder if it is really such an edge case.

As I didn't recognize that solution immediately, I have already created an extended Map function. Feel free to merge or reject it.

Clindbergh avatar Nov 29 '21 20:11 Clindbergh