nullability fixes
This commit is contained in:
@@ -4,7 +4,7 @@ using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
namespace MaybeError;
|
||||
|
||||
public interface IMaybe<T, E> where T: class where E : Error
|
||||
public interface IMaybe<T, E> where E : Error
|
||||
{
|
||||
[MemberNotNullWhen(true, nameof(Error))]
|
||||
bool HasError { get; }
|
||||
@@ -46,7 +46,7 @@ public interface IMaybe<T, E> where T: class where E : Error
|
||||
}
|
||||
}
|
||||
|
||||
public readonly struct Maybe<T, E> : IMaybe<T, E> where T : class where E: Error
|
||||
public readonly struct Maybe<T, E> : IMaybe<T, E> where E: Error
|
||||
{
|
||||
[MemberNotNullWhen(true, nameof(Error))]
|
||||
public readonly bool HasError { get; }
|
||||
@@ -101,7 +101,7 @@ public readonly struct Maybe<T, E> : IMaybe<T, E> where T : class where E: Error
|
||||
}
|
||||
|
||||
|
||||
public readonly struct Maybe<T> : IMaybe<T, Error> where T : class
|
||||
public readonly struct Maybe<T> : IMaybe<T, Error>
|
||||
{
|
||||
[MemberNotNullWhen(true, nameof(Error))]
|
||||
public readonly bool HasError { get; }
|
||||
|
||||
@@ -38,33 +38,33 @@ public static class MaybeExtensions
|
||||
}
|
||||
|
||||
|
||||
public static T ValueOrDefault<T, E>(this IMaybe<T, E> maybe, T defaultValue) where T : class where E : Error
|
||||
public static T ValueOrDefault<T, E>(this IMaybe<T, E> maybe, T defaultValue) where E : Error
|
||||
{
|
||||
if (maybe.HasError)
|
||||
return defaultValue;
|
||||
return maybe.Value;
|
||||
}
|
||||
|
||||
public static T? ValueOrDefault<T, E>(this IMaybe<T, E> maybe) where T : class where E : Error
|
||||
public static T? ValueOrDefault<T, E>(this IMaybe<T, E> maybe) where E : Error
|
||||
{
|
||||
if (maybe.HasError)
|
||||
return default;
|
||||
return maybe.Value;
|
||||
}
|
||||
|
||||
public static R As<R, T, E>(this IMaybe<T, E> maybe, Func<T, R> predicate) where T : class where E : Error
|
||||
public static R As<R, T, E>(this IMaybe<T, E> maybe, Func<T, R> predicate) where E : Error
|
||||
{
|
||||
return predicate(maybe.Value);
|
||||
}
|
||||
|
||||
public static R? AsOrDefault<R, T, E>(this IMaybe<T, E> maybe, Func<T, R> predicate) where T : class where E : Error
|
||||
public static R? AsOrDefault<R, T, E>(this IMaybe<T, E> maybe, Func<T, R> predicate) where E : Error
|
||||
{
|
||||
if (maybe.HasError)
|
||||
return default;
|
||||
return predicate(maybe.Value);
|
||||
}
|
||||
|
||||
public static R AsOrDefault<R, T, E>(this IMaybe<T, E> maybe, Func<T, R> predicate, R defaultValue) where T : class where E : Error
|
||||
public static R AsOrDefault<R, T, E>(this IMaybe<T, E> maybe, Func<T, R> predicate, R defaultValue) where E : Error
|
||||
{
|
||||
if (maybe.HasError)
|
||||
return defaultValue;
|
||||
|
||||
Reference in New Issue
Block a user