Sweetener 1.0.0-beta.3

This is a prerelease version of Sweetener.

Requires NuGet 4.9.0 or higher.

dotnet add package Sweetener --version 1.0.0-beta.3
NuGet\Install-Package Sweetener -Version 1.0.0-beta.3
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Sweetener" Version="1.0.0-beta.3" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Sweetener --version 1.0.0-beta.3
#r "nuget: Sweetener, 1.0.0-beta.3"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Sweetener as a Cake Addin
#addin nuget:?package=Sweetener&version=1.0.0-beta.3&prerelease

// Install Sweetener as a Cake Tool
#tool nuget:?package=Sweetener&version=1.0.0-beta.3&prerelease

Sweetener

GitHub License Sweetener Build Sweetener Code Coverage

The Sweetener library contains a set of APIs that extends the .NET Base Class Libraries (BCLs). New functionality is built on top of both the BCLs' data types and the new types introduced by Sweetener. This README provides examples for a subset of these new APIs.

New Types

Sweetener introduces new types for common scenarios.

Delegates

In addition to Action and Func<TOut>, Sweetener adds asynchronous and "try" delegates.

using System.IO;
using Sweetener;

// TryFunc<TOut>
TryFunc<string, int> tryParse = int.TryParse;
bool result = tryParse("12345", out int number);

// AsyncAction
using StreamWriter writer = /* ... */;
AsyncAction<string?> writeLineAsync = writer.WriteLineAsync;
await writeLineAsync("Hello World!").ConfigureAwait(false);

// AsyncFunc<TOut>
using StreamReader reader = /* ... */;
AsyncFunc<string?> readLineAsync = reader.ReadLineAsync;
string? line = await readLineAsync().ConfigureAwait(false);

Optional<T>

While Nullable<T> creates a type union of null and value types, the Optional<T> class represents some value of type T or no value at all. In this way, methods can choose to optionally return a value of type T. This may be especially helpful for asynchronous methods that attempt to return a value but are unable to use out parameters.

using System;
using Sweetener;

Optional<string?> response = await TryReadMessageAsync().ConfigureAwait(false);
if (response.TryGetValue(out string? message))
    Console.WriteLine("Received: " + message);
else
    Console.WriteLine("Did not receive response");

New Functionality

Sweetener adds additional functionality for many of the BCL APIs.

BinaryComparer

For data types that represent binary data, like byte[], Stream, and ReadOnlySpan<byte>, comparisons can be made using the BinaryComparer class.

using System.Collections.Generic;
using Sweetener.Collections.Generic;

byte[] a = /* ... */;
byte[] b = /* ... */;

// IComparer<T>
IComparer<byte[]> comparer = BinaryComparer.Instance;
int cmp = comparer.Compare(a, b);

// IEqualityComparer<T>
IEqualityComparer<byte[]> equalityComparer = BinaryComparer.Instance;
bool areEqual = equalityComparer.Equals(a, b);
int hashCode = equalityComparer.GetHashCode(a);

MultiTask

Unlike Task.WhenAll(Task[]), the MultiTask class allows users to wait on the completion of multiple heterogeneous tasks whose type arguments differ from one another.

using System;
using System.Threading.Tasks;
using Sweetener.Threading.Tasks;

Task<int> task1 = /* ... */;
Task<string> task2 = /* ... */;
Task<DateTime> task3 = /* ... */;

(int n, string s, DateTime d) = await MultiTask.WhenAll(task1, task2, task3).ConfigureAwait(false);
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on Sweetener:

Package Downloads
Sweetener.Reliability

API for executing user-defined delegates despite transient failures

Sweetener.Linq

APIs that sweeten System.Linq in the .NET base class libraries

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.0-beta.3 373 6/11/2022
1.0.0-beta.2 164 5/11/2021
1.0.0-beta.1 399 6/2/2020
1.0.0-alpha.2 308 3/20/2020