Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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
# In almost all cases in dotnet core this is unnecessary as there is no synchronization context

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HA!

dotnet_diagnostic.CA2007.severity = none
3 changes: 0 additions & 3 deletions wimm.Secundatives.UnitTests/Extensions/AsMaybe_Test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ public async Task AsMaybeTaskClass_Null_ReturnsNone()
Assert.Equal(Maybe<string>.None, res);
}


[Fact]
public async Task AsMaybeTaskClass_Value_ReturnsSome()
{
Expand Down Expand Up @@ -85,7 +84,5 @@ public async Task AsMaybeTaskNullable_Value_ReturnsSome()

Assert.Equal(25, res.Value);
}


}
}
4 changes: 0 additions & 4 deletions wimm.Secundatives.UnitTests/Extensions/Expect_Test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ public void ExpectMessage_WhiteSpaceMessage_Throws()
Assert.Throws<ArgumentException>("message", () => underTest.Expect(" \t\r\n"));
}


[Fact]
public void ExpectMessage_DoesNotExist_ThrowsWithMessage()
{
Expand Down Expand Up @@ -85,8 +84,5 @@ public async Task ExpectTaskMessage_Value_ReturnsValue()
var underTest = Task.FromResult(new Maybe<int>(10));
Assert.Equal(10, await underTest.Expect(_message));
}



}
}
1 change: 0 additions & 1 deletion wimm.Secundatives.UnitTests/Extensions/Flatten_Test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ public void Flatten_InnerExistsAndIsValue_ReturnsValue()
Assert.Equal(value, res.Value);
}


[Fact]
public void Flatten_InnerExistsAndIsError_ReturnsError()
{
Expand Down
7 changes: 0 additions & 7 deletions wimm.Secundatives.UnitTests/Extensions/OkOr_Test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ public void OkOrFunc_None_ReturnsFuncResultAsError()
Assert.Equal(TestingEnum.BadThingsHappened, result.Error);
}


[Fact]
public void OkOrErrorValue_Value_ReturnsResultWithValue()
{
Expand All @@ -46,7 +45,6 @@ public void OkOrErrorValue_None_ReturnsErrorValue()
Assert.Equal(TestingEnum.BadThingsHappened, result.Error);
}


[Fact]
public async Task OkOrErrorTaskFunc_Value_ReturnsResultWithValue()
{
Expand All @@ -56,7 +54,6 @@ public async Task OkOrErrorTaskFunc_Value_ReturnsResultWithValue()
Assert.Equal("doot", result.Value);
}


[Fact]
public async Task OkOrErrorTaskFunc_None_ReturnsResultWithValue()
{
Expand All @@ -67,7 +64,6 @@ public async Task OkOrErrorTaskFunc_None_ReturnsResultWithValue()

}


[Fact]
public async Task OkOrErrorTaskValue_Value_ReturnsResultWithValue()
{
Expand Down Expand Up @@ -123,12 +119,9 @@ public async Task OkOrErrorTaskFunc_ResultMemberIsNone_ReturnsInternalResult()
Assert.Equal(TestingEnum.BadThingsHappened, result.Error);
}


public enum TestingEnum
{
BadThingsHappened
}


}
}
4 changes: 0 additions & 4 deletions wimm.Secundatives.UnitTests/Extensions/ResultMapping_Test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ public async Task MapTaskResult_IsErrorAndFuncReturnsValue_ReturnsError()
Assert.Equal(TestError.Sadness, res.Error);
}


[Fact]
public async Task MapTaskResult_IsSuccessAndFuncReturnsTask_ReturnsResultOfFunc()
{
Expand Down Expand Up @@ -133,7 +132,6 @@ public void MapErrorValue_IsErrorAndFuncReturnsValue_ReturnsResultOfFunc()
Assert.Equal(OtherError.OtherSadness, res.Error);
}


[Fact]
public void MapErrorValue_IsSuccessAndFuncReturnsValue_ReturnsValue()
{
Expand Down Expand Up @@ -203,7 +201,6 @@ private static Result<T, TestError> ConstructWith<T>(T value)
return new Result<T, TestError>(value);
}


private enum TestError
{
Sadness
Expand All @@ -213,6 +210,5 @@ private enum OtherError
{
OtherSadness
}

}
}
14 changes: 11 additions & 3 deletions wimm.Secundatives.UnitTests/Extensions/UnwrapOr_Test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,17 @@ public class UnwrapOr_Test
{
private const string _valid = "doot";
private const string _default = "tood";
private readonly Func<string> _defaultFunc = () => { _set = true; return _default; };
private readonly Func<Task<string>> _defaultAsyncFunc = async () => { _set = true; ; return await Task.FromResult(_default); };
private readonly Func<string> _defaultFunc = () =>
{
_set = true;
return _default;
};
private readonly Func<Task<string>> _defaultAsyncFunc = async () =>
{
_set = true;
return await Task.FromResult(_default);
};

private static bool _set = false;

public UnwrapOr_Test()
Expand Down Expand Up @@ -40,7 +49,6 @@ public void UnwrawpOrFunc_NoValue_ExecutesFunction()
Assert.Equal(_default, underTest.UnwrapOr(_defaultFunc));
}


[Fact]
public void UnwrapOr_NoValue_ReturnsDefaultParam()
{
Expand Down
3 changes: 0 additions & 3 deletions wimm.Secundatives.UnitTests/Maybe_Test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ namespace wimm.Secundatives.UnitTests
public class Maybe_Test
{


[Fact]
public void Construct_ValueTypeDefault_EqualsNone()
{
Expand Down Expand Up @@ -349,7 +348,5 @@ public void GetHashCode_ValueMaybe_Throws()

Assert.Throws<InvalidOperationException>(() => underTest.GetHashCode());
}


}
}
9 changes: 2 additions & 7 deletions wimm.Secundatives.UnitTests/Result_Test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -14,7 +14,6 @@ public void Error_ContainsValue_Throws()
Assert.Throws<InvalidOperationException>(() => underTest.Error);
}


[Fact]
public void Value_ContainsError_Throws()
{
Expand All @@ -29,7 +28,6 @@ public void Error_ContainsError_ReturnsError()
Assert.Equal(_err, underTest.Error);
}


[Fact]
public void Value_ContainsValue_ReturnsValue()
{
Expand Down Expand Up @@ -92,9 +90,7 @@ public void Ok_ContainsError_ReturnsNone()
var underTest = ConstructErr();
Assert.False(underTest.Ok().Exists);
}


private Result<int> ConstructInt()
private static Result<int> ConstructInt()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you mean to leave no empty lines here?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not

{
return 42;
}
Expand All @@ -103,6 +99,5 @@ private Result<int> ConstructErr()
{
return _err;
}

}
}
9 changes: 8 additions & 1 deletion wimm.Secundatives.UnitTests/TestHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,20 @@ public class TestHelpers
{
private static readonly List<string> _stringControls = new() { "\t", "\r", "\n", " " };


public static void AssertThrowsIfWhitespace(Action<string> action)
{
foreach (var control in _stringControls)
{
Assert.Throws<ArgumentException>(() => action(control));
}
}

public static void AssertThrowsIfWhitespace<T>(Func<string, T> action)
{
foreach (var control in _stringControls)
{
Assert.Throws<ArgumentException>(() => action(control));
}
}
}
}
3 changes: 0 additions & 3 deletions wimm.Secundatives.UnitTests/Variant_Test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,8 @@ private static Variant<int, string> ConstructInt()
return new Variant<int, string>(42);
}



class Base { }
class Derived : Base { }
class OtherDerived : Base { }

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>

<IsPackable>false</IsPackable>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ public static class ApplyFunctionsExtensions
/// </exception>
public static TFunc Apply<TArg, TFunc>(this TArg target, Func<TArg, TFunc> 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);
}

Expand All @@ -53,8 +55,10 @@ public static TFunc Apply<TArg, TFunc>(this TArg target, Func<TArg, TFunc> fn, b
/// </exception>
public static bool In<T>(this T target, IEnumerable<T> 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<T>.Default);
}
}
Expand Down
4 changes: 4 additions & 0 deletions wimm.Secundatives/Extensions/FlattenExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
/// </returns>
public static Result<TValue, TErr> Flatten<TValue, TErr>(this Result<Result<TValue, TErr>, TErr> result)
where TValue : notnull

@ttd2089 ttd2089 Aug 14, 2022

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea I think this is breaking

I was going to say I think code using NRT (like this) would interpret code not using NRT as though all its types were nullable and then this constraint wouldn't be satisfied. Thinking a bit more though I'm not sure what notnull means in non-NRT contexts. If it means value types then this is breaking, but if it means not declared with ? then it's probably fine?

We should just try it. I'll do it after supper if you don't beat me to it.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All good.

The notnull constraint is available starting in C# 8.0 for code compiled in a nullable enable context. Unlike other constraints, if a type argument violates the notnull constraint, the compiler generates a warning instead of an error. Warnings are only generated in a nullable enable context.
- https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/where-generic-type-constraint

where TErr : notnull
{
return result.IsValue ? result.Value : result.Error;
}
Expand All @@ -31,6 +33,8 @@ public static Result<TValue, TErr> Flatten<TValue, TErr>(this Result<Result<TVal
/// A task containing the un-nested result of inspecting the outer result for error and returning it if it exists or the nested result itself otherwise
/// </returns>
public static async Task<Result<TValue, TErr>> Flatten<TValue, TErr>(this Task<Result<Result<TValue, TErr>, TErr>> res)
where TValue : notnull
where TErr : notnull
{
var result = await res;
return result.IsValue ? result.Value : result.Error;
Expand Down
7 changes: 0 additions & 7 deletions wimm.Secundatives/Extensions/MaybeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ public static class MaybeExtensions
/// <returns> The <typeparamref name="T"/> held within <paramref name="maybe"/> if it exists. </returns>
public static T Expect<T>(this Maybe<T> maybe) => maybe.Expect($"Expected value in {nameof(Maybe<T>)}");


/// Extension to indicate that a value missing from a <see cref="Maybe{T}"/> is unrecoverable.
/// Unwraps the <see cref="Maybe{T}"/> if it exists or throws a <see cref="ExpectException"/>
/// with a custom message.
Expand Down Expand Up @@ -54,7 +53,6 @@ public static async Task<T> Expect<T>(this Task<Maybe<T>> maybeTask, string mess
return (await maybeTask).Expect(message);
}


/// <summary>
/// Helper function to apply <see cref="Expect{T}(Maybe{T})"/> in async contexts. Awaits the task containing the <see cref="Maybe{T}"/>
/// and then applies the <see cref="Expect{T}(Maybe{T})"/> function to it.
Expand All @@ -68,7 +66,6 @@ public static async Task<T> Expect<T>(this Task<Maybe<T>> maybeTask)
return (await maybeTask).Expect();
}


/// <summary>
/// Unwraps the <see cref="Maybe{T}"/> if possible and returns a provided default otherwise
/// </summary>
Expand All @@ -80,7 +77,6 @@ public static async Task<T> Expect<T>(this Task<Maybe<T>> maybeTask)
/// <paramref name="defaultValue"/> </returns>
public static T UnwrapOr<T>(this Maybe<T> maybe, T defaultValue) => maybe.Exists ? maybe.Value : defaultValue;


/// <summary>
/// Unwraps the <see cref="Maybe{T}"/> if possible and returns the results of a provided function otherwise
/// </summary>
Expand All @@ -103,7 +99,6 @@ public static async Task<T> Expect<T>(this Task<Maybe<T>> maybeTask)
/// the result of awaiting the execution of <paramref name="func"/> </returns>
public static async Task<T> UnwrapOr<T>(this Maybe<T> maybe, Func<Task<T>> func) => maybe.Exists ? maybe.Value : await func();


/// <summary>
/// Unwraps the <see cref="Maybe{T}"/> that results from the <see cref="Task"/> if possible and returns the results of awaiting the provided async function otherwise
/// </summary>
Expand Down Expand Up @@ -160,7 +155,6 @@ public static Maybe<T> AsMaybe<T>(this T? value) where T : struct
return value.HasValue ? new Maybe<T>(value.Value) : Maybe<T>.None;
}


/// <summary>
/// Helper function that awaits a <see cref="Task{T}"/>'s result and converts it into a <see cref="Maybe{T}"/>
/// </summary>
Expand All @@ -175,7 +169,6 @@ public static async Task<Maybe<T>> AsMaybe<T>(this Task<T> value) where T : clas
return (await value).AsMaybe();
}


/// <summary>
/// Helper function that awaits a <see cref="Task{T}"/>'s nullable result and converts it into a <see cref="Maybe{T}"/>
/// </summary>
Expand Down
Loading