added implicit operator

This commit is contained in:
2025-04-03 13:48:36 -04:00
parent ee5eeedb50
commit ce71765cb4
2 changed files with 8 additions and 1 deletions

View File

@@ -33,4 +33,9 @@ public class ExceptionError<T> : Error where T : Exception
{
return $"{Message}\n{Exception}";
}
public static implicit operator ExceptionError<T>(T exception)
{
return new ExceptionError<T>(exception);
}
}

View File

@@ -51,7 +51,7 @@ public readonly struct Maybe<T, E> : IMaybe<T, E> where E: Error
[MemberNotNullWhen(true, nameof(Error))]
public readonly bool HasError { get; }
public readonly bool HasValue => !HasError;
public readonly E? Error { get; }
public readonly E? Error { get; init; }
public readonly T Value => HasError ? throw Error.GetException() : _value!;
private readonly T? _value;
@@ -82,6 +82,7 @@ public readonly struct Maybe<T, E> : IMaybe<T, E> where E: Error
_value = default;
}
public static implicit operator Maybe<T, E>(T value)
{
return new Maybe<T, E>(value);
@@ -92,6 +93,7 @@ public readonly struct Maybe<T, E> : IMaybe<T, E> where E: Error
return new Maybe<T, E>(e);
}
public static implicit operator T(Maybe<T, E> value)
{
if (value.HasError)