Closed punmechanic closed 7 years ago
Hi,
The currently recommended way to do this is:
var values = options.SelectMany(option => option.ToEnumerable());
However, as of version 4 which is just around the corner, this will be provided as an extension method directly:
using Optional.Collections;
...
var values = options.Flatten();
The exact name of the extension method is still something I am considering though, and it might end up as options.Values()
instead, to allow a similar extension method for Option<T, TException>
exceptional values (options.Exceptions()
).
Hope it helps.
/Nils
Cool, thanks!
What would be the correct way to transform an IEnumerable of Option to simply an IEnumerable of T?
Let's say for example that I have a list of values and I only care about the ones that definitely have values and would like to both filter out the ones that are
None
as well as cause the type signature to match.