I am fresh new with the brilliant language-ext c# library.
I have this code that returns a Try<IEnumerable<Try<Unit>> object:
Try(DetectAlertsToNotify)
.MapT(SendNotification)
//treat errors happened indifferently from their source
Edit: DetectAlertsToNotify returns an IEnumerable of AlertDTO
What I would like to achieve is to process elegantly all exceptions or maybe the first exception whatever it happened in DetectAlertsToNotify or SendNotification.
How could I aggregate all errors or take the first error of Try<IEnumerable<Try<Unit>> with keeping code simple and minimum as possible?
Maybe you're looking for something like this:
Notes:
Arr<T>instead ofIEnumerable<T>because this makes sure there is no enumeration outside ofTryin case the exception might raise when enumerating. Otherwise we probably need some helper to make sure the enumeration itself is catched in someTry.Sequence()will change inner and outer monad (container). This turnsArr<Try<Unit>>intoTry<Arr<Unit>>. We need this because we want/need to "stay" in theTrymonad (LINQ expression).If you look at the intermediate types you probably will get the idea.