Skip to content

Instantly share code, notes, and snippets.

@nojaf
Last active September 15, 2017 07:43
Show Gist options
  • Save nojaf/a3eb9f1d1cffa395e700c449c14b88a3 to your computer and use it in GitHub Desktop.
Save nojaf/a3eb9f1d1cffa395e700c449c14b88a3 to your computer and use it in GitHub Desktop.
public static Option<TException> WithoutValue<TValue, TException>(this Option<TValue, TException> option)
{
return option.Match(_ => Option.None<TException>(), exception => exception.Some());
}
public static IEnumerable<TValue> Values<TValue, TException>(this IEnumerable<Option<TValue, TException>> source)
{
if (source == null) throw new ArgumentNullException(nameof(source));
return source.SelectMany(option => option.ToEnumerable());
}
public static IEnumerable<TException> Exceptions<TValue, TException>(this IEnumerable<Option<TValue, TException>> source)
{
if (source == null) throw new ArgumentNullException(nameof(source));
return source.SelectMany(option => option.WithoutValue().ToEnumerable());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment