14 Commits
11 changed files with 150 additions and 20 deletions
+2 -2
View File
@@ -2,8 +2,8 @@
[![NuGet](https://img.shields.io/nuget/v/StevanFreeborn.Results.svg)](https://www.nuget.org/packages/StevanFreeborn.Results)
[![NuGet](https://img.shields.io/nuget/dt/StevanFreeborn.Results.svg)](https://www.nuget.org/packages/StevanFreeborn.Results)
[![Build](https://github.com/StevanFreeborn/stevanfreeborn.results/actions/workflows/ci.yaml/badge.svg)](https://github.com/StevanFreeborn/stevanfreeborn.results/actions/workflows/ci.yaml)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![Build](https://gitea.freeborn.cloud/Stevan/stevanfreeborn.results/actions/workflows/ci.yml/badge.svg)](https://gitea.freeborn.cloud/Stevan/stevanfreeborn.results/actions?workflow=ci.yml)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](./LICENSE.md)
A minimalistic, AOT-compatible Result type library with support for custom error types, for railway-oriented programming and functional error handling in .NET.
+6 -4
View File
@@ -2,7 +2,10 @@ param(
[string]$Branch = "main"
)
$commits = git log $Branch..HEAD --format="%s"
$tag = git describe --tags --abbrev=0 2>$null
$base = if ($tag) { $tag } else { $Branch }
$commits = git log "$base..HEAD" --format="%s"
$commitList = $commits -split "`n"
$major = 0
$minor = 0
@@ -11,9 +14,9 @@ $patch = 0
foreach ($message in $commitList) {
if ($message -match " BREAKING CHANGE|!:" -and $message.Trim().Length -gt 0) {
$major = 1
} elseif ($message -match "^feat(\(.*\))?:" -and $message.Trim().Length -gt 0) {
} elseif ($message -match "feat(\(.*\))?:" -and $message.Trim().Length -gt 0) {
$minor = 1
} elseif ($message -match "^fix(\(.*\))?:" -and $message.Trim().Length -gt 0) {
} elseif ($message -match "fix(\(.*\))?:" -and $message.Trim().Length -gt 0) {
$patch = 1
}
}
@@ -28,7 +31,6 @@ if ($major -eq 1) {
}
$currentVersion = "0.0.0"
$tag = git describe --tags --abbrev=0 2>$null
$hasExistingTag = $false
if ($tag) {
+8 -6
View File
@@ -2,7 +2,10 @@
branch="${1:-main}"
commits=$(git log "$branch..HEAD" --format="%s")
tag=$(git describe --tags --abbrev=0 2>/dev/null)
base="${tag:-$branch}"
commits=$(git log "$base..HEAD" --format="%s")
major=0
minor=0
patch=0
@@ -10,9 +13,9 @@ patch=0
while IFS= read -r message; do
if [[ -n "$message" ]] && [[ "$message" =~ " BREAKING CHANGE|!:" ]]; then
major=1
elif [[ -n "$message" ]] && [[ "$message" =~ ^feat(\(.*\))?: ]]; then
elif [[ -n "$message" ]] && [[ "$message" =~ feat(\(.*\))?: ]]; then
minor=1
elif [[ -n "$message" ]] && [[ "$message" =~ ^fix(\(.*\))?: ]]; then
elif [[ -n "$message" ]] && [[ "$message" =~ fix(\(.*\))?: ]]; then
patch=1
fi
done <<< "$commits"
@@ -27,7 +30,6 @@ elif [[ "$patch" -eq 0 ]] && [[ -n "$commits" ]]; then
fi
currentVersion="0.0.0"
tag=$(git describe --tags --abbrev=0 2>/dev/null)
hasExistingTag=false
if [[ -n "$tag" ]]; then
@@ -54,12 +56,12 @@ fi
if [[ "$majorNew" -eq "$majorCurrent" ]] && [[ "$minorNew" -eq "$minorCurrent" ]] && [[ "$patchNew" -eq "$patchCurrent" ]]; then
if [[ "$hasExistingTag" == "false" ]]; then
version="0.0.0"
echo "VERSION=$version" >> "$GITHUB_OUTPUT"
[[ -n "$GITHUB_OUTPUT" ]] && echo "VERSION=$version" >> "$GITHUB_OUTPUT" || echo "VERSION=$version"
echo "First release: publishing version 0.0.0"
else
exit 0
fi
else
version="$majorNew.$minorNew.$patchNew"
echo "VERSION=$version" >> "$GITHUB_OUTPUT"
[[ -n "$GITHUB_OUTPUT" ]] && echo "VERSION=$version" >> "$GITHUB_OUTPUT" || echo "VERSION=$version"
fi
-1
View File
@@ -1,5 +1,4 @@
[*.cs]
dotnet_diagnostic.CA1031.severity = none
dotnet_diagnostic.CA1510.severity = none
dotnet_diagnostic.CA2225.severity = none
+44
View File
@@ -53,15 +53,23 @@ namespace StevanFreeborn.Results
/// <exception cref="ArgumentNullException">Thrown when func or errorHandler is null.</exception>
public static Result<T, TError> Try<T, TError>(Func<T> func, Func<Exception, TError> errorHandler) where TError : IError
{
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(func);
#else
if (func is null)
{
throw new ArgumentNullException(nameof(func));
}
#endif
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(errorHandler);
#else
if (errorHandler is null)
{
throw new ArgumentNullException(nameof(errorHandler));
}
#endif
try
{
@@ -142,10 +150,14 @@ namespace StevanFreeborn.Results
/// <exception cref="ArgumentNullException">Thrown when mapper is null.</exception>
public Result<TNew, TError> Map<TNew>(Func<T, TNew> mapper)
{
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(mapper);
#else
if (mapper is null)
{
throw new ArgumentNullException(nameof(mapper));
}
#endif
return IsSuccess ? Result.Ok<TNew, TError>(mapper(Value)) : Result.Fail<TNew, TError>(Error);
}
@@ -158,10 +170,14 @@ namespace StevanFreeborn.Results
/// <exception cref="ArgumentNullException">Thrown when mapper is null.</exception>
public Result<T, TNewError> MapError<TNewError>(Func<TError, TNewError> mapper) where TNewError : IError
{
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(mapper);
#else
if (mapper is null)
{
throw new ArgumentNullException(nameof(mapper));
}
#endif
return IsFailure ? Result.Fail<T, TNewError>(mapper(Error)) : Result.Ok<T, TNewError>(Value);
}
@@ -175,10 +191,14 @@ namespace StevanFreeborn.Results
/// <exception cref="ArgumentNullException">Thrown when binder is null.</exception>
public Result<TNew, TError> Bind<TNew>(Func<T, Result<TNew, TError>> binder)
{
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(binder);
#else
if (binder is null)
{
throw new ArgumentNullException(nameof(binder));
}
#endif
return IsSuccess ? binder(Value) : Result.Fail<TNew, TError>(Error);
}
@@ -193,15 +213,23 @@ namespace StevanFreeborn.Results
/// <exception cref="ArgumentNullException">Thrown when onSuccess or onFailure is null.</exception>
public TResult Match<TResult>(Func<T, TResult> onSuccess, Func<TError, TResult> onFailure)
{
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(onSuccess);
#else
if (onSuccess is null)
{
throw new ArgumentNullException(nameof(onSuccess));
}
#endif
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(onFailure);
#else
if (onFailure is null)
{
throw new ArgumentNullException(nameof(onFailure));
}
#endif
return IsSuccess ? onSuccess(Value) : onFailure(Error);
}
@@ -214,15 +242,23 @@ namespace StevanFreeborn.Results
/// <exception cref="ArgumentNullException">Thrown when onSuccess or onFailure is null.</exception>
public void Match(Action<T> onSuccess, Action<TError> onFailure)
{
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(onSuccess);
#else
if (onSuccess is null)
{
throw new ArgumentNullException(nameof(onSuccess));
}
#endif
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(onFailure);
#else
if (onFailure is null)
{
throw new ArgumentNullException(nameof(onFailure));
}
#endif
if (IsSuccess)
{
@@ -242,10 +278,14 @@ namespace StevanFreeborn.Results
/// <exception cref="ArgumentNullException">Thrown when action is null.</exception>
public Result<T, TError> Map(Action<T> action)
{
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(action);
#else
if (action is null)
{
throw new ArgumentNullException(nameof(action));
}
#endif
if (IsSuccess)
{
@@ -262,10 +302,14 @@ namespace StevanFreeborn.Results
/// <exception cref="ArgumentNullException">Thrown when action is null.</exception>
public Result<T, TError> Map(Action action)
{
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(action);
#else
if (action is null)
{
throw new ArgumentNullException(nameof(action));
}
#endif
if (IsSuccess)
{
@@ -19,15 +19,23 @@ namespace StevanFreeborn.Results
public static async Task<Result<TNew, TError>> MapAsync<T, TNew, TError>(this Result<T, TError> result, Func<T, Task<TNew>> mapper)
where TError : IError
{
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(result);
#else
if (result is null)
{
throw new ArgumentNullException(nameof(result));
}
#endif
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(mapper);
#else
if (mapper is null)
{
throw new ArgumentNullException(nameof(mapper));
}
#endif
return result.IsSuccess ? await mapper(result.Value).ConfigureAwait(false) : result.Error;
}
@@ -46,15 +54,23 @@ namespace StevanFreeborn.Results
where TError : IError
where TNewError : IError
{
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(result);
#else
if (result is null)
{
throw new ArgumentNullException(nameof(result));
}
#endif
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(mapper);
#else
if (mapper is null)
{
throw new ArgumentNullException(nameof(mapper));
}
#endif
return result.IsFailure ? await mapper(result.Error).ConfigureAwait(false) : Result.Ok<T, TNewError>(result.Value);
}
@@ -70,15 +86,23 @@ namespace StevanFreeborn.Results
public static async Task<Result<Unit, TError>> MapAsync<TError>(this Result<Unit, TError> result, Func<Unit, Task> onSuccess)
where TError : IError
{
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(result);
#else
if (result is null)
{
throw new ArgumentNullException(nameof(result));
}
#endif
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(onSuccess);
#else
if (onSuccess is null)
{
throw new ArgumentNullException(nameof(onSuccess));
}
#endif
if (result.IsSuccess)
{
@@ -99,15 +123,23 @@ namespace StevanFreeborn.Results
public static async Task<Result<Unit, TError>> BindAsync<TError>(this Result<Unit, TError> result, Func<Unit, Task<Result<Unit, TError>>> onSuccess)
where TError : IError
{
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(result);
#else
if (result is null)
{
throw new ArgumentNullException(nameof(result));
}
#endif
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(onSuccess);
#else
if (onSuccess is null)
{
throw new ArgumentNullException(nameof(onSuccess));
}
#endif
return result.IsSuccess ? await onSuccess(result.Value).ConfigureAwait(false) : result;
}
@@ -125,20 +157,32 @@ namespace StevanFreeborn.Results
public static async Task<TResult> MatchAsync<TResult, TError>(this Result<Unit, TError> result, Func<Unit, Task<TResult>> onSuccess, Func<TError, Task<TResult>> onFailure)
where TError : IError
{
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(result);
#else
if (result is null)
{
throw new ArgumentNullException(nameof(result));
}
#endif
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(onSuccess);
#else
if (onSuccess is null)
{
throw new ArgumentNullException(nameof(onSuccess));
}
#endif
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(onFailure);
#else
if (onFailure is null)
{
throw new ArgumentNullException(nameof(onFailure));
}
#endif
return result.IsSuccess
? await onSuccess(result.Value).ConfigureAwait(false)
@@ -164,15 +208,23 @@ namespace StevanFreeborn.Results
/// <exception cref="ArgumentNullException">Thrown when action or errorHandler is null.</exception>
public static async Task<Result<Unit, Error>> TryAsync(Func<Task> action, Func<Exception, Error> errorHandler)
{
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(action);
#else
if (action is null)
{
throw new ArgumentNullException(nameof(action));
}
#endif
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(errorHandler);
#else
if (errorHandler is null)
{
throw new ArgumentNullException(nameof(errorHandler));
}
#endif
try
{
@@ -198,15 +250,23 @@ namespace StevanFreeborn.Results
public static async Task<Result<TNew, TError>> BindAsync<T, TNew, TError>(this Result<T, TError> result, Func<T, Task<Result<TNew, TError>>> binder)
where TError : IError
{
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(result);
#else
if (result is null)
{
throw new ArgumentNullException(nameof(result));
}
#endif
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(binder);
#else
if (binder is null)
{
throw new ArgumentNullException(nameof(binder));
}
#endif
return result.IsSuccess ? await binder(result.Value).ConfigureAwait(false) : Result.Fail<TNew, TError>(result.Error);
}
@@ -225,20 +285,32 @@ namespace StevanFreeborn.Results
public static async Task<TResult> MatchAsync<T, TResult, TError>(this Result<T, TError> result, Func<T, Task<TResult>> onSuccess, Func<TError, Task<TResult>> onFailure)
where TError : IError
{
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(result);
#else
if (result is null)
{
throw new ArgumentNullException(nameof(result));
}
#endif
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(onSuccess);
#else
if (onSuccess is null)
{
throw new ArgumentNullException(nameof(onSuccess));
}
#endif
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(onFailure);
#else
if (onFailure is null)
{
throw new ArgumentNullException(nameof(onFailure));
}
#endif
return result.IsSuccess
? await onSuccess(result.Value).ConfigureAwait(false)
@@ -266,15 +338,23 @@ namespace StevanFreeborn.Results
/// <exception cref="ArgumentNullException">Thrown when func or errorHandler is null.</exception>
public static async Task<Result<T, Error>> TryAsync<T>(Func<Task<T>> func, Func<Exception, Error> errorHandler)
{
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(func);
#else
if (func is null)
{
throw new ArgumentNullException(nameof(func));
}
#endif
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(errorHandler);
#else
if (errorHandler is null)
{
throw new ArgumentNullException(nameof(errorHandler));
}
#endif
try
{
@@ -7,7 +7,7 @@
</PropertyGroup>
<PropertyGroup>
<PackageId>StevanFreeborn.Results</PackageId>
<Version>0.0.0</Version>
<Version>0.0.3</Version>
<Authors>Stevan Freeborn</Authors>
<Description>A minimalistic, AOT-compatible Result type library for railway-oriented programming and functional error handling.</Description>
<PackageTags>result;railway;functional;error-handling;discriminated-union</PackageTags>
@@ -16,11 +16,14 @@
<RepositoryType>git</RepositoryType>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<EmbedUntrackedSources>true</EmbedUntrackedSources>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<DebugType>embedded</DebugType>
<PackageReadmeFile>README.md</PackageReadmeFile>
<PackageLicenseFile>LICENSE.md</PackageLicenseFile>
</PropertyGroup>
<PropertyGroup Condition="'$(GITEA_ACTIONS)' == 'true'">
<ContinuousIntegrationBuild>true</ContinuousIntegrationBuild>
</PropertyGroup>
<ItemGroup>
<None Include="..\..\README.md" Pack="true" PackagePath="\" />
<None Include="..\..\LICENSE.md" Pack="true" PackagePath="\" />