Added First or None to IOption
All checks were successful
Build NuGet / build (push) Successful in 44s
All checks were successful
Build NuGet / build (push) Successful in 44s
This commit is contained in:
@@ -84,4 +84,16 @@ public static class OptionExtensions
|
|||||||
|
|
||||||
public static Option<T> ToStructOption<T>(this IOption<T> option) => option.HasValue(out var value) ? Option<T>.Some(value) : Option<T>.None;
|
public static Option<T> ToStructOption<T>(this IOption<T> option) => option.HasValue(out var value) ? Option<T>.Some(value) : Option<T>.None;
|
||||||
public static IOption<T> ToClassOption<T>(this Option<T> option) => option.HasValue ? option.Value.ToOption() : None<T>.Of();
|
public static IOption<T> ToClassOption<T>(this Option<T> option) => option.HasValue ? option.Value.ToOption() : None<T>.Of();
|
||||||
|
public static IOption<T> FirstOrNone<T>(this IEnumerable<T> options) => options.Any() ? options.First().ToOption() : None<T>.Of();
|
||||||
|
public static IOption<T> FirstOrNone<T>(this IEnumerable<T> options, Predicate<T> predicate)
|
||||||
|
{
|
||||||
|
foreach (var item in options)
|
||||||
|
{
|
||||||
|
if (predicate(item))
|
||||||
|
{
|
||||||
|
return item.ToOption();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return None<T>.Of();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user