From 9269b4b5b3a0e85e04e3b1b437a251418ed4cc11 Mon Sep 17 00:00:00 2001 From: Chris Nantau Date: Sun, 14 Aug 2022 10:31:43 -0300 Subject: [PATCH 1/5] feat: enabled nullability and changed formatting standards to our newer editorconfig --- .editorconfig | 4 ++-- .../Extensions/AsMaybe_Test.cs | 3 --- .../Extensions/Expect_Test.cs | 4 ---- .../Extensions/Flatten_Test.cs | 1 - .../Extensions/OkOr_Test.cs | 7 ------- .../Extensions/ResultMapping_Test.cs | 4 ---- .../Extensions/UnwrapOr_Test.cs | 14 +++++++++++--- wimm.Secundatives.UnitTests/Maybe_Test.cs | 3 --- wimm.Secundatives.UnitTests/Result_Test.cs | 9 ++------- wimm.Secundatives.UnitTests/TestHelpers.cs | 9 ++++++++- wimm.Secundatives.UnitTests/Variant_Test.cs | 3 --- .../ApplyFunctionsExtensions.cs | 12 ++++++++---- wimm.Secundatives/Extensions/MaybeExtensions.cs | 7 ------- wimm.Secundatives/Extensions/OkOrExtensions.cs | 5 ----- .../Extensions/ResultMappingExtensions.cs | 6 ------ wimm.Secundatives/Extensions/VariantExtensions.cs | 1 - wimm.Secundatives/Maybe.cs | 8 ++++---- wimm.Secundatives/NaturalRange.cs | 7 ++++--- wimm.Secundatives/Range.cs | 11 ++++++----- wimm.Secundatives/Result.cs | 12 ++++-------- wimm.Secundatives/Variant.cs | 14 ++++---------- wimm.Secundatives/wimm.Secundatives.csproj | 1 + 22 files changed, 54 insertions(+), 91 deletions(-) diff --git a/.editorconfig b/.editorconfig index 733ebd8..d49bcf8 100644 --- a/.editorconfig +++ b/.editorconfig @@ -218,5 +218,5 @@ dotnet_naming_style.underscore_camel.capitalization = camel_case dotnet_analyzer_diagnostic.category-Globalization.severity = none # CA2007: Consider calling ConfigureAwait on the awaited task -# In almost all cases in dotnet core this is unnecessary as there is syncronization context -dotnet_diagnostic.CA2007.severity = none \ No newline at end of file +# In almost all cases in dotnet core this is unnecessary as there is no synchronization context +dotnet_diagnostic.CA2007.severity = none diff --git a/wimm.Secundatives.UnitTests/Extensions/AsMaybe_Test.cs b/wimm.Secundatives.UnitTests/Extensions/AsMaybe_Test.cs index 5e95879..59e75e2 100644 --- a/wimm.Secundatives.UnitTests/Extensions/AsMaybe_Test.cs +++ b/wimm.Secundatives.UnitTests/Extensions/AsMaybe_Test.cs @@ -55,7 +55,6 @@ public async Task AsMaybeTaskClass_Null_ReturnsNone() Assert.Equal(Maybe.None, res); } - [Fact] public async Task AsMaybeTaskClass_Value_ReturnsSome() { @@ -85,7 +84,5 @@ public async Task AsMaybeTaskNullable_Value_ReturnsSome() Assert.Equal(25, res.Value); } - - } } diff --git a/wimm.Secundatives.UnitTests/Extensions/Expect_Test.cs b/wimm.Secundatives.UnitTests/Extensions/Expect_Test.cs index 0e0ae15..e8b35ff 100644 --- a/wimm.Secundatives.UnitTests/Extensions/Expect_Test.cs +++ b/wimm.Secundatives.UnitTests/Extensions/Expect_Test.cs @@ -25,7 +25,6 @@ public void ExpectMessage_WhiteSpaceMessage_Throws() Assert.Throws("message", () => underTest.Expect(" \t\r\n")); } - [Fact] public void ExpectMessage_DoesNotExist_ThrowsWithMessage() { @@ -85,8 +84,5 @@ public async Task ExpectTaskMessage_Value_ReturnsValue() var underTest = Task.FromResult(new Maybe(10)); Assert.Equal(10, await underTest.Expect(_message)); } - - - } } diff --git a/wimm.Secundatives.UnitTests/Extensions/Flatten_Test.cs b/wimm.Secundatives.UnitTests/Extensions/Flatten_Test.cs index d4c99d1..fed9a38 100644 --- a/wimm.Secundatives.UnitTests/Extensions/Flatten_Test.cs +++ b/wimm.Secundatives.UnitTests/Extensions/Flatten_Test.cs @@ -27,7 +27,6 @@ public void Flatten_InnerExistsAndIsValue_ReturnsValue() Assert.Equal(value, res.Value); } - [Fact] public void Flatten_InnerExistsAndIsError_ReturnsError() { diff --git a/wimm.Secundatives.UnitTests/Extensions/OkOr_Test.cs b/wimm.Secundatives.UnitTests/Extensions/OkOr_Test.cs index b7a7d25..fcb71fb 100644 --- a/wimm.Secundatives.UnitTests/Extensions/OkOr_Test.cs +++ b/wimm.Secundatives.UnitTests/Extensions/OkOr_Test.cs @@ -25,7 +25,6 @@ public void OkOrFunc_None_ReturnsFuncResultAsError() Assert.Equal(TestingEnum.BadThingsHappened, result.Error); } - [Fact] public void OkOrErrorValue_Value_ReturnsResultWithValue() { @@ -46,7 +45,6 @@ public void OkOrErrorValue_None_ReturnsErrorValue() Assert.Equal(TestingEnum.BadThingsHappened, result.Error); } - [Fact] public async Task OkOrErrorTaskFunc_Value_ReturnsResultWithValue() { @@ -56,7 +54,6 @@ public async Task OkOrErrorTaskFunc_Value_ReturnsResultWithValue() Assert.Equal("doot", result.Value); } - [Fact] public async Task OkOrErrorTaskFunc_None_ReturnsResultWithValue() { @@ -67,7 +64,6 @@ public async Task OkOrErrorTaskFunc_None_ReturnsResultWithValue() } - [Fact] public async Task OkOrErrorTaskValue_Value_ReturnsResultWithValue() { @@ -123,12 +119,9 @@ public async Task OkOrErrorTaskFunc_ResultMemberIsNone_ReturnsInternalResult() Assert.Equal(TestingEnum.BadThingsHappened, result.Error); } - public enum TestingEnum { BadThingsHappened } - - } } diff --git a/wimm.Secundatives.UnitTests/Extensions/ResultMapping_Test.cs b/wimm.Secundatives.UnitTests/Extensions/ResultMapping_Test.cs index 77d6b03..5c4fecd 100644 --- a/wimm.Secundatives.UnitTests/Extensions/ResultMapping_Test.cs +++ b/wimm.Secundatives.UnitTests/Extensions/ResultMapping_Test.cs @@ -64,7 +64,6 @@ public async Task MapTaskResult_IsErrorAndFuncReturnsValue_ReturnsError() Assert.Equal(TestError.Sadness, res.Error); } - [Fact] public async Task MapTaskResult_IsSuccessAndFuncReturnsTask_ReturnsResultOfFunc() { @@ -133,7 +132,6 @@ public void MapErrorValue_IsErrorAndFuncReturnsValue_ReturnsResultOfFunc() Assert.Equal(OtherError.OtherSadness, res.Error); } - [Fact] public void MapErrorValue_IsSuccessAndFuncReturnsValue_ReturnsValue() { @@ -203,7 +201,6 @@ private static Result ConstructWith(T value) return new Result(value); } - private enum TestError { Sadness @@ -213,6 +210,5 @@ private enum OtherError { OtherSadness } - } } diff --git a/wimm.Secundatives.UnitTests/Extensions/UnwrapOr_Test.cs b/wimm.Secundatives.UnitTests/Extensions/UnwrapOr_Test.cs index 8515d9f..bbffc70 100644 --- a/wimm.Secundatives.UnitTests/Extensions/UnwrapOr_Test.cs +++ b/wimm.Secundatives.UnitTests/Extensions/UnwrapOr_Test.cs @@ -9,8 +9,17 @@ public class UnwrapOr_Test { private const string _valid = "doot"; private const string _default = "tood"; - private readonly Func _defaultFunc = () => { _set = true; return _default; }; - private readonly Func> _defaultAsyncFunc = async () => { _set = true; ; return await Task.FromResult(_default); }; + private readonly Func _defaultFunc = () => + { + _set = true; + return _default; + }; + private readonly Func> _defaultAsyncFunc = async () => + { + _set = true; + return await Task.FromResult(_default); + }; + private static bool _set = false; public UnwrapOr_Test() @@ -40,7 +49,6 @@ public void UnwrawpOrFunc_NoValue_ExecutesFunction() Assert.Equal(_default, underTest.UnwrapOr(_defaultFunc)); } - [Fact] public void UnwrapOr_NoValue_ReturnsDefaultParam() { diff --git a/wimm.Secundatives.UnitTests/Maybe_Test.cs b/wimm.Secundatives.UnitTests/Maybe_Test.cs index c64c0ce..cca64ae 100644 --- a/wimm.Secundatives.UnitTests/Maybe_Test.cs +++ b/wimm.Secundatives.UnitTests/Maybe_Test.cs @@ -6,7 +6,6 @@ namespace wimm.Secundatives.UnitTests public class Maybe_Test { - [Fact] public void Construct_ValueTypeDefault_EqualsNone() { @@ -349,7 +348,5 @@ public void GetHashCode_ValueMaybe_Throws() Assert.Throws(() => underTest.GetHashCode()); } - - } } diff --git a/wimm.Secundatives.UnitTests/Result_Test.cs b/wimm.Secundatives.UnitTests/Result_Test.cs index 82fc807..129c8c4 100644 --- a/wimm.Secundatives.UnitTests/Result_Test.cs +++ b/wimm.Secundatives.UnitTests/Result_Test.cs @@ -5,7 +5,7 @@ namespace wimm.Secundatives.UnitTests { public class Result_Test { - private readonly Error _err = new Error("BadDoot"); + private readonly Error _err = new("BadDoot"); [Fact] public void Error_ContainsValue_Throws() @@ -14,7 +14,6 @@ public void Error_ContainsValue_Throws() Assert.Throws(() => underTest.Error); } - [Fact] public void Value_ContainsError_Throws() { @@ -29,7 +28,6 @@ public void Error_ContainsError_ReturnsError() Assert.Equal(_err, underTest.Error); } - [Fact] public void Value_ContainsValue_ReturnsValue() { @@ -92,9 +90,7 @@ public void Ok_ContainsError_ReturnsNone() var underTest = ConstructErr(); Assert.False(underTest.Ok().Exists); } - - - private Result ConstructInt() + private static Result ConstructInt() { return 42; } @@ -103,6 +99,5 @@ private Result ConstructErr() { return _err; } - } } diff --git a/wimm.Secundatives.UnitTests/TestHelpers.cs b/wimm.Secundatives.UnitTests/TestHelpers.cs index 9d70dfe..5926372 100644 --- a/wimm.Secundatives.UnitTests/TestHelpers.cs +++ b/wimm.Secundatives.UnitTests/TestHelpers.cs @@ -8,7 +8,6 @@ public class TestHelpers { private static readonly List _stringControls = new() { "\t", "\r", "\n", " " }; - public static void AssertThrowsIfWhitespace(Action action) { foreach (var control in _stringControls) @@ -16,5 +15,13 @@ public static void AssertThrowsIfWhitespace(Action action) Assert.Throws(() => action(control)); } } + + public static void AssertThrowsIfWhitespace(Func action) + { + foreach (var control in _stringControls) + { + Assert.Throws(() => action(control)); + } + } } } diff --git a/wimm.Secundatives.UnitTests/Variant_Test.cs b/wimm.Secundatives.UnitTests/Variant_Test.cs index 9662069..52820e4 100644 --- a/wimm.Secundatives.UnitTests/Variant_Test.cs +++ b/wimm.Secundatives.UnitTests/Variant_Test.cs @@ -90,11 +90,8 @@ private static Variant ConstructInt() return new Variant(42); } - - class Base { } class Derived : Base { } class OtherDerived : Base { } - } } diff --git a/wimm.Secundatives/ApplyFunctionsExtensions/ApplyFunctionsExtensions.cs b/wimm.Secundatives/ApplyFunctionsExtensions/ApplyFunctionsExtensions.cs index 2964779..4e17d83 100644 --- a/wimm.Secundatives/ApplyFunctionsExtensions/ApplyFunctionsExtensions.cs +++ b/wimm.Secundatives/ApplyFunctionsExtensions/ApplyFunctionsExtensions.cs @@ -28,8 +28,10 @@ public static class ApplyFunctionsExtensions /// public static TFunc Apply(this TArg target, Func fn, bool allowNull = false) { - if (target == null && !allowNull) throw new ArgumentNullException(nameof(target)); - if (fn == null) throw new ArgumentNullException(nameof(fn)); + if (target == null && !allowNull) + throw new ArgumentNullException(nameof(target)); + if (fn == null) + throw new ArgumentNullException(nameof(fn)); return fn(target); } @@ -53,8 +55,10 @@ public static TFunc Apply(this TArg target, Func fn, b /// public static bool In(this T target, IEnumerable enumerable, bool allowNull = false) { - if (target == null && !allowNull) throw new ArgumentNullException(nameof(target)); - if (enumerable == null) throw new ArgumentNullException(nameof(enumerable)); + if (target == null && !allowNull) + throw new ArgumentNullException(nameof(target)); + if (enumerable == null) + throw new ArgumentNullException(nameof(enumerable)); return enumerable.Contains(target, EqualityComparer.Default); } } diff --git a/wimm.Secundatives/Extensions/MaybeExtensions.cs b/wimm.Secundatives/Extensions/MaybeExtensions.cs index 96f1471..89687ce 100644 --- a/wimm.Secundatives/Extensions/MaybeExtensions.cs +++ b/wimm.Secundatives/Extensions/MaybeExtensions.cs @@ -20,7 +20,6 @@ public static class MaybeExtensions /// The held within if it exists. public static T Expect(this Maybe maybe) => maybe.Expect($"Expected value in {nameof(Maybe)}"); - /// Extension to indicate that a value missing from a is unrecoverable. /// Unwraps the if it exists or throws a /// with a custom message. @@ -54,7 +53,6 @@ public static async Task Expect(this Task> maybeTask, string mess return (await maybeTask).Expect(message); } - /// /// Helper function to apply in async contexts. Awaits the task containing the /// and then applies the function to it. @@ -68,7 +66,6 @@ public static async Task Expect(this Task> maybeTask) return (await maybeTask).Expect(); } - /// /// Unwraps the if possible and returns a provided default otherwise /// @@ -80,7 +77,6 @@ public static async Task Expect(this Task> maybeTask) /// public static T UnwrapOr(this Maybe maybe, T defaultValue) => maybe.Exists ? maybe.Value : defaultValue; - /// /// Unwraps the if possible and returns the results of a provided function otherwise /// @@ -103,7 +99,6 @@ public static async Task Expect(this Task> maybeTask) /// the result of awaiting the execution of public static async Task UnwrapOr(this Maybe maybe, Func> func) => maybe.Exists ? maybe.Value : await func(); - /// /// Unwraps the that results from the if possible and returns the results of awaiting the provided async function otherwise /// @@ -160,7 +155,6 @@ public static Maybe AsMaybe(this T? value) where T : struct return value.HasValue ? new Maybe(value.Value) : Maybe.None; } - /// /// Helper function that awaits a 's result and converts it into a /// @@ -175,7 +169,6 @@ public static async Task> AsMaybe(this Task value) where T : clas return (await value).AsMaybe(); } - /// /// Helper function that awaits a 's nullable result and converts it into a /// diff --git a/wimm.Secundatives/Extensions/OkOrExtensions.cs b/wimm.Secundatives/Extensions/OkOrExtensions.cs index 6af815a..9c297ac 100644 --- a/wimm.Secundatives/Extensions/OkOrExtensions.cs +++ b/wimm.Secundatives/Extensions/OkOrExtensions.cs @@ -30,7 +30,6 @@ public static Result OkOr(this Maybe value, Func /// Maps a into a by returning a default value if /// is None. In the case where contains a value returns a @@ -51,7 +50,6 @@ public static Result OkOr(this Maybe value, TError erro return error; } - /// /// Maps a containing a into a by returning a default value if /// is None. In the case where contains a value returns a @@ -70,7 +68,6 @@ public static async Task> OkOr(this Task> return v.OkOr(error); } - /// /// Maps a containing a into a by executing if /// is None. In the case where contains a value returns a @@ -90,7 +87,6 @@ public static async Task> OkOr(this Task> } - /// /// Collapsing mapping of a containing a that may hold a /// into a @@ -108,7 +104,6 @@ public static async Task> OkOr(this Task /// Collapsing mapping of a containing a that may hold a /// into a diff --git a/wimm.Secundatives/Extensions/ResultMappingExtensions.cs b/wimm.Secundatives/Extensions/ResultMappingExtensions.cs index f5d8647..fe95cd7 100644 --- a/wimm.Secundatives/Extensions/ResultMappingExtensions.cs +++ b/wimm.Secundatives/Extensions/ResultMappingExtensions.cs @@ -33,7 +33,6 @@ public static Result Map(this Result result, return result.Error; } - /// /// Transforms a into a by applying an async function if the mapped /// contains a value otherwise by constructing a new from the @@ -78,7 +77,6 @@ public static async Task> Map(this Task /// Asynchronously transforms a into a by applying an async function and collapsing /// the result if the mapped contains a value otherwise by constructing a new @@ -101,7 +99,6 @@ public static async Task> Map(this Task /// Asynchronously transforms a into a by applying an async function and collapsing /// the result if the mapped contains a value otherwise by constructing a new @@ -126,7 +123,6 @@ public static async Task> Map(this Result /// Asynchronously transforms a into a by applying an async function and collapsing /// the result if the mapped contains a value otherwise by constructing a new @@ -152,7 +148,6 @@ public static async Task> Map(this Task /// Transforms a into a by applying a function if the mapped /// contains a . Otherwise constructs a new @@ -176,7 +171,6 @@ public static Result MapError(this Result /// Asynchronously transforms a into a by applying a function if the mapped /// contains a . Otherwise constructs a new diff --git a/wimm.Secundatives/Extensions/VariantExtensions.cs b/wimm.Secundatives/Extensions/VariantExtensions.cs index d8acad0..477accc 100644 --- a/wimm.Secundatives/Extensions/VariantExtensions.cs +++ b/wimm.Secundatives/Extensions/VariantExtensions.cs @@ -26,7 +26,6 @@ public static class VariantExtensions public static W MapValue(this Variant variant, Func tMapping, Func uMapping) => variant.Is() ? tMapping(variant.Get()) : uMapping(variant.Get()); - /// /// Maps the contents of a variant to an action taking that type. Executes the function matching the type of the value /// diff --git a/wimm.Secundatives/Maybe.cs b/wimm.Secundatives/Maybe.cs index 20006e2..c0d1d33 100644 --- a/wimm.Secundatives/Maybe.cs +++ b/wimm.Secundatives/Maybe.cs @@ -11,7 +11,7 @@ public static class Maybe /// /// A static instance of None to reduce memory pressure and to facilitate simple conversions /// - public static readonly None None = new None(); + public static readonly None None = new(); } /// @@ -65,7 +65,7 @@ public Maybe(T value) public override bool Equals(object obj) { - if (!(obj is Maybe maybe)) + if (obj is not Maybe maybe) return false; return Equals(maybe); @@ -77,9 +77,9 @@ public bool Equals(Maybe other) && EqualityComparer.Default.Equals(_value, other._value); } - public static implicit operator Maybe(T value) => new Maybe(value); + public static implicit operator Maybe(T value) => new(value); - public static implicit operator Maybe(None _) => new Maybe(); + public static implicit operator Maybe(None _) => new(); #pragma warning restore CS1591 // Missing XML comment for publicly visible type or member diff --git a/wimm.Secundatives/NaturalRange.cs b/wimm.Secundatives/NaturalRange.cs index 8545f54..1494820 100644 --- a/wimm.Secundatives/NaturalRange.cs +++ b/wimm.Secundatives/NaturalRange.cs @@ -11,7 +11,6 @@ public class NaturalRange : IRange private const string _outOfRangeMessage = "Must be greater than or equal to zero."; private readonly Range _range; - /// /// /// @@ -41,8 +40,10 @@ public NaturalRange(int max) : this(0, max) { } /// public NaturalRange(int min, int max) { - if (min < 0) throw new ArgumentOutOfRangeException(nameof(min), _outOfRangeMessage); - if (max < 0) throw new ArgumentOutOfRangeException(nameof(max), _outOfRangeMessage); + if (min < 0) + throw new ArgumentOutOfRangeException(nameof(min), _outOfRangeMessage); + if (max < 0) + throw new ArgumentOutOfRangeException(nameof(max), _outOfRangeMessage); if (max < min) throw new ArgumentException( diff --git a/wimm.Secundatives/Range.cs b/wimm.Secundatives/Range.cs index 60e2e45..87600f8 100644 --- a/wimm.Secundatives/Range.cs +++ b/wimm.Secundatives/Range.cs @@ -26,8 +26,8 @@ public class Range : IRange where T : IComparable /// public Range(T min, T max) { - Min = Require(min, nameof(min)); - Max = Require(max, nameof(max)); + Min = Range.Require(min, nameof(min)); + Max = Range.Require(max, nameof(max)); if (max.CompareTo(min) < 0) throw new ArgumentException( @@ -41,14 +41,15 @@ public Range(T min, T max) /// true if is greater than and less than public bool Includes(T value) { - Require(value, nameof(value)); + Range.Require(value, nameof(value)); return !(Min.CompareTo(value) > 0 || Max.CompareTo(value) < 0); } - private T Require(T value, string name) + private static T Require(T value, string name) { - if (value == null) throw new ArgumentNullException(name); + if (value == null) + throw new ArgumentNullException(name); return value; } } diff --git a/wimm.Secundatives/Result.cs b/wimm.Secundatives/Result.cs index 78396a8..9d8e2cd 100644 --- a/wimm.Secundatives/Result.cs +++ b/wimm.Secundatives/Result.cs @@ -16,7 +16,6 @@ public class Result : Variant /// A value indicating if the operation successfully returned a value public bool IsValue => Is(); - /// Gets the value contained in the result. /// The result contains no value - operation failed public T Value => Get(); @@ -47,13 +46,11 @@ public Result(TError err) : base(err) //CN(justification): These operators are trivial and their documentation would just be code bloat #pragma warning disable CS1591 // Missing XML comment for publicly visible type or member - public static implicit operator Result(T value) => new Result(value); - public static implicit operator Result(TError error) => new Result(error); + public static implicit operator Result(T value) => new(value); + public static implicit operator Result(TError error) => new(error); #pragma warning restore CS1591 // Missing XML comment for publicly visible type or member } - - /// /// A basic Result class that handles operations with a possibility of failure that uses a special error class to /// report failure @@ -78,9 +75,8 @@ public Result(Error err) : base(err) //CN(justification): These operators are trivial and their documentation would just be code bloat #pragma warning disable CS1591 // Missing XML comment for publicly visible type or member - public static implicit operator Result(T value) => new Result(value); - public static implicit operator Result(Error error) => new Result(error); + public static implicit operator Result(T value) => new(value); + public static implicit operator Result(Error error) => new(error); #pragma warning restore CS1591 // Missing XML comment for publicly visible type or member } - } diff --git a/wimm.Secundatives/Variant.cs b/wimm.Secundatives/Variant.cs index 67ebc94..c72ca99 100644 --- a/wimm.Secundatives/Variant.cs +++ b/wimm.Secundatives/Variant.cs @@ -41,7 +41,7 @@ public bool Is() { var wType = typeof(W); - if (!IsAssignableFromMemberType(wType)) + if (!Variant.IsAssignableFromMemberType(wType)) throw UnsupportedType(wType, new List { typeof(T), typeof(U) }); return _value is W; @@ -80,12 +80,11 @@ public Variant(U value) //CN(justification): These operators are trivial and their documentation would just be code bloat #pragma warning disable CS1591 // Missing XML comment for publicly visible type or member - public static implicit operator Variant(T val) => new Variant(val); - public static implicit operator Variant(U val) => new Variant(val); + public static implicit operator Variant(T val) => new(val); + public static implicit operator Variant(U val) => new(val); #pragma warning restore CS1591 // Missing XML comment for publicly visible type or member - - private bool IsAssignableFromMemberType(Type type) + private static bool IsAssignableFromMemberType(Type type) { return typeof(U).IsAssignableFrom(type) || typeof(T).IsAssignableFrom(type); } @@ -101,10 +100,5 @@ private static NotSupportedException UnsupportedType(Type expected, IEnumerable< return new NotSupportedException( $"Variant was checked for type it cannot contain:\nRequested:{expected}\nAvailable: {string.Join("\n", available)}"); } - - - } - - } diff --git a/wimm.Secundatives/wimm.Secundatives.csproj b/wimm.Secundatives/wimm.Secundatives.csproj index 7616ed5..a53e145 100644 --- a/wimm.Secundatives/wimm.Secundatives.csproj +++ b/wimm.Secundatives/wimm.Secundatives.csproj @@ -11,6 +11,7 @@ https://github.com/wareismymind/secundatives git true + warnings From 123509496ed916a7db2168079ada3256977a9864 Mon Sep 17 00:00:00 2001 From: Chris Nantau Date: Sun, 14 Aug 2022 11:28:46 -0300 Subject: [PATCH 2/5] feat: add nullable annotations for real and add notnull attribute to all generics --- .../Extensions/FlattenExtensions.cs | 4 +++ .../Extensions/OkOrExtensions.cs | 12 ++++++++ .../Extensions/ResultMappingExtensions.cs | 30 +++++++++++++++++++ .../Extensions/VariantExtensions.cs | 6 ++++ wimm.Secundatives/Maybe.cs | 2 +- wimm.Secundatives/Result.cs | 3 ++ wimm.Secundatives/Variant.cs | 4 ++- wimm.Secundatives/wimm.Secundatives.csproj | 2 +- 8 files changed, 60 insertions(+), 3 deletions(-) diff --git a/wimm.Secundatives/Extensions/FlattenExtensions.cs b/wimm.Secundatives/Extensions/FlattenExtensions.cs index 0cad7e3..027cd5f 100644 --- a/wimm.Secundatives/Extensions/FlattenExtensions.cs +++ b/wimm.Secundatives/Extensions/FlattenExtensions.cs @@ -17,6 +17,8 @@ public static class FlattenExtensions /// The un-nested result of inspecting the outer result for error and returning it if it exists or the nested result itself otherwise /// public static Result Flatten(this Result, TErr> result) + where TValue : notnull + where TErr : notnull { return result.IsValue ? result.Value : result.Error; } @@ -31,6 +33,8 @@ public static Result Flatten(this Result public static async Task> Flatten(this Task, TErr>> res) + where TValue : notnull + where TErr : notnull { var result = await res; return result.IsValue ? result.Value : result.Error; diff --git a/wimm.Secundatives/Extensions/OkOrExtensions.cs b/wimm.Secundatives/Extensions/OkOrExtensions.cs index 9c297ac..839265e 100644 --- a/wimm.Secundatives/Extensions/OkOrExtensions.cs +++ b/wimm.Secundatives/Extensions/OkOrExtensions.cs @@ -23,6 +23,8 @@ public static class OkOrExtensions /// contains the result of executing /// public static Result OkOr(this Maybe value, Func func) + where T : notnull + where TError : notnull { if (value.Exists) return value.Value; @@ -43,6 +45,8 @@ public static Result OkOr(this Maybe value, Func /// public static Result OkOr(this Maybe value, TError error) + where T : notnull + where TError : notnull { if (value.Exists) return value.Value; @@ -63,6 +67,8 @@ public static Result OkOr(this Maybe value, TError erro /// contains /// public static async Task> OkOr(this Task> value, TError error) + where T : notnull + where TError : notnull { var v = await value; return v.OkOr(error); @@ -81,6 +87,8 @@ public static async Task> OkOr(this Task> /// contains the result of executing /// public static async Task> OkOr(this Task> value, Func func) + where T : notnull + where TError : notnull { var v = await value; return v.OkOr(func); @@ -99,6 +107,8 @@ public static async Task> OkOr(this Task> /// A either contained by if it exists or created /// from if it is None public static async Task> OkOr(this Task>> value, TError error) + where T : notnull + where TError : notnull { var res = await value; return res.UnwrapOr(error); @@ -116,6 +126,8 @@ public static async Task> OkOr(this Task A either contained by if it exists or created /// from the results of calling if it is None public static async Task> OkOr(this Task>> value, Func func) + where T : notnull + where TError : notnull { var res = await value; return res.UnwrapOr(func()); diff --git a/wimm.Secundatives/Extensions/ResultMappingExtensions.cs b/wimm.Secundatives/Extensions/ResultMappingExtensions.cs index fe95cd7..7abedee 100644 --- a/wimm.Secundatives/Extensions/ResultMappingExtensions.cs +++ b/wimm.Secundatives/Extensions/ResultMappingExtensions.cs @@ -26,6 +26,9 @@ public static class ResultMappingExtensions /// if it exists. Otherwise returns a containing the contained within /// public static Result Map(this Result result, Func func) + where T : notnull + where U : notnull + where TError : notnull { if (result.IsValue) return func(result.Value); @@ -50,6 +53,9 @@ public static Result Map(this Result result, /// if it exists. Otherwise returns a containing the contained within /// public static async Task> Map(this Result result, Func> func) + where T : notnull + where U : notnull + where TError : notnull { if (result.IsValue) return await func(result.Value); @@ -72,6 +78,9 @@ public static async Task> Map(this Resultif it exists. Otherwise returns a containing the /// contained within public static async Task> Map(this Task> result, Func func) + where T : notnull + where U : notnull + where TError : notnull { var val = await result; return val.Map(func); @@ -93,6 +102,9 @@ public static async Task> Map(this Task if it exists. Otherwise returns a containing the /// contained within public static async Task> Map(this Task> result, Func> func) + where T : notnull + where U : notnull + where TError : notnull { var res = await result; @@ -116,6 +128,9 @@ public static async Task> Map(this Task containing the contained within /// public static async Task> Map(this Result result, Func>> func) + where T : notnull + where U : notnull + where TError : notnull { if (result.IsValue) return await func(result.Value); @@ -140,6 +155,9 @@ public static async Task> Map(this Result containing the contained within /// public static async Task> Map(this Task> result, Func>> func) + where T : notnull + where U : notnull + where TError : notnull { var res = await result; if (res.IsValue) @@ -164,6 +182,9 @@ public static async Task> Map(this Task of if it exists. Otherwise returns a /// containing the contained within public static Result MapError(this Result result, Func func) + where T : notnull + where TError : notnull + where UError : notnull { if (result.IsError) return func(result.Error); @@ -187,6 +208,9 @@ public static Result MapError(this Result of if it exists. Otherwise returns a /// containing the contained within public static async Task> MapError(this Task> result, Func func) + where T : notnull + where TError : notnull + where UError : notnull { var val = await result; return val.MapError(func); @@ -208,6 +232,9 @@ public static async Task> MapError(this Tas /// name="result"/> or by calling on the error from /// public static U MapOr(this Result result, Func valueFunc, Func errorFunc) + where T : notnull + where U : notnull + where TError : notnull { return result.IsValue ? valueFunc(result.Value) : errorFunc(result.Error); } @@ -228,6 +255,9 @@ public static U MapOr(this Result result, Func va /// name="result"/> or by calling on the error from /// public static async Task MapOr(this Task> result, Func valueFunc, Func errorFunc) + where T : notnull + where U : notnull + where TError : notnull { var res = await result; return res.IsValue ? valueFunc(res.Value) : errorFunc(res.Error); diff --git a/wimm.Secundatives/Extensions/VariantExtensions.cs b/wimm.Secundatives/Extensions/VariantExtensions.cs index 477accc..99cbd1c 100644 --- a/wimm.Secundatives/Extensions/VariantExtensions.cs +++ b/wimm.Secundatives/Extensions/VariantExtensions.cs @@ -24,6 +24,10 @@ public static class VariantExtensions /// contains a value of type /// public static W MapValue(this Variant variant, Func tMapping, Func uMapping) + where T : notnull + where U : notnull + where W : notnull + => variant.Is() ? tMapping(variant.Get()) : uMapping(variant.Get()); /// @@ -41,6 +45,8 @@ public static W MapValue(this Variant variant, Func tMappin /// is /// public static void MapAction(this Variant variant, Action tAction, Action uAction) + where T : notnull + where U : notnull { if (variant.Is()) tAction(variant.Get()); diff --git a/wimm.Secundatives/Maybe.cs b/wimm.Secundatives/Maybe.cs index c0d1d33..85495a7 100644 --- a/wimm.Secundatives/Maybe.cs +++ b/wimm.Secundatives/Maybe.cs @@ -63,7 +63,7 @@ public Maybe(T value) public static bool operator !=(Maybe left, Maybe right) => !left.Equals(right); - public override bool Equals(object obj) + public override bool Equals(object? obj) { if (obj is not Maybe maybe) return false; diff --git a/wimm.Secundatives/Result.cs b/wimm.Secundatives/Result.cs index 9d8e2cd..b110456 100644 --- a/wimm.Secundatives/Result.cs +++ b/wimm.Secundatives/Result.cs @@ -9,6 +9,8 @@ namespace wimm.Secundatives /// /// public class Result : Variant + where T : notnull + where TError : notnull { /// A value indicating whether the operation resulted in an error type public bool IsError => Is(); @@ -57,6 +59,7 @@ public Result(TError err) : base(err) /// /// The type to be returned on success public class Result : Result + where T : notnull { /// diff --git a/wimm.Secundatives/Variant.cs b/wimm.Secundatives/Variant.cs index c72ca99..4028fca 100644 --- a/wimm.Secundatives/Variant.cs +++ b/wimm.Secundatives/Variant.cs @@ -6,7 +6,9 @@ namespace wimm.Secundatives /// /// A typesafe union that contains either a or a /// - public class Variant + public class Variant + where T : notnull + where U : notnull { /// /// Ensures that and are not within the same diff --git a/wimm.Secundatives/wimm.Secundatives.csproj b/wimm.Secundatives/wimm.Secundatives.csproj index a53e145..911256a 100644 --- a/wimm.Secundatives/wimm.Secundatives.csproj +++ b/wimm.Secundatives/wimm.Secundatives.csproj @@ -11,7 +11,7 @@ https://github.com/wareismymind/secundatives git true - warnings + enable From 0d26b6c518a2fdf3e5c330d94f9f6da47d762503 Mon Sep 17 00:00:00 2001 From: Chris Nantau Date: Sun, 14 Aug 2022 11:32:30 -0300 Subject: [PATCH 3/5] rm newline --- wimm.Secundatives.UnitTests/wimm.Secundatives.UnitTests.csproj | 1 - 1 file changed, 1 deletion(-) diff --git a/wimm.Secundatives.UnitTests/wimm.Secundatives.UnitTests.csproj b/wimm.Secundatives.UnitTests/wimm.Secundatives.UnitTests.csproj index e10f72c..845aa9c 100644 --- a/wimm.Secundatives.UnitTests/wimm.Secundatives.UnitTests.csproj +++ b/wimm.Secundatives.UnitTests/wimm.Secundatives.UnitTests.csproj @@ -2,7 +2,6 @@ net6.0 - false From 7f75f095bd15137086589a926d0458fd6a022f36 Mon Sep 17 00:00:00 2001 From: Chris Nantau Date: Sun, 14 Aug 2022 11:54:12 -0300 Subject: [PATCH 4/5] chore: twae settings - closes #67 --- wimm.Secundatives/wimm.Secundatives.csproj | 1 - 1 file changed, 1 deletion(-) diff --git a/wimm.Secundatives/wimm.Secundatives.csproj b/wimm.Secundatives/wimm.Secundatives.csproj index 911256a..ac68570 100644 --- a/wimm.Secundatives/wimm.Secundatives.csproj +++ b/wimm.Secundatives/wimm.Secundatives.csproj @@ -16,7 +16,6 @@ true - 1591 From 07ae86ace65d5ae43c29c234817f4a520d953318 Mon Sep 17 00:00:00 2001 From: Chris Nantau Date: Sun, 14 Aug 2022 11:57:11 -0300 Subject: [PATCH 5/5] no differences between release and debug now remove conditional blocks in csproj --- wimm.Secundatives/wimm.Secundatives.csproj | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/wimm.Secundatives/wimm.Secundatives.csproj b/wimm.Secundatives/wimm.Secundatives.csproj index ac68570..eabca77 100644 --- a/wimm.Secundatives/wimm.Secundatives.csproj +++ b/wimm.Secundatives/wimm.Secundatives.csproj @@ -11,16 +11,7 @@ https://github.com/wareismymind/secundatives git true - enable + true + enable - - - true - - - - - true - -