dotUnit 1.0.0

dotnet add package dotUnit --version 1.0.0
                    
NuGet\Install-Package dotUnit -Version 1.0.0
                    
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="dotUnit" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="dotUnit" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="dotUnit" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add dotUnit --version 1.0.0
                    
#r "nuget: dotUnit, 1.0.0"
                    
#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.
#:package dotUnit@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=dotUnit&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=dotUnit&version=1.0.0
                    
Install as a Cake Tool

dotUnit

NuGet version

dotUnit is an ultra-lightweight C# library that provides a Unit type. Its purpose is to serve as a functional programming equivalent for void, enabling more consistent and composable code, especially in generic contexts.

Why dotUnit?

In C#, void is a keyword, not a type. This creates limitations when working with generic types like Task<T> or custom functional constructs like Result<TSuccess, TError>. You cannot use void as a generic type argument:

// This is not valid C# code
Task<void> DoSomethingAsync(); 
Result<void, Error> DoSomething();

The common workaround is to use an empty, meaningless struct. dotUnit formalizes this concept by providing a standardized, explicit Unit type, signaling that a method is executed for its side effect, returning no meaningful value.

Using Unit makes your intentions clear and allows "void" methods to be first-class citizens in your functional code.

  • Task<Unit> vs Task: Task<Unit> is more explicit and composable in functional chains.

  • Result<Unit, Error>: Clearly represents a successful operation that produces no value.

This package is inspired by the unit type found in functional languages like F# and Haskell.

Installation You can install dotUnit via the .NET CLI:

dotnet add package dotUnit

Or via the NuGet Package Manager:

Install-Package dotUnit

How to Use

Simply return Unit.Instance from any method that would otherwise return void.

Basic Example Instead of this:

public void LogMessage(string message)
{
    Console.WriteLine(message);
}

You can write this:

using DotUnit;

public Unit LogMessage(string message)
{
    Console.WriteLine(message);
    return Unit.Instance;
}

Asynchronous Example

Using Task<Unit> makes asynchronous workflows that don't return a value more composable.

using DotUnit;
using System.Threading.Tasks;

public async Task<Unit> UpdateCacheAsync()
{
    // Perform some async work...
    await Task.Delay(100); 
    
    Console.WriteLine("Cache updated.");
    
    return Unit.Instance;
}

With a Result Type dotUnit works perfectly with functional constructs like a Result monad (for example, with a library like dotResult).

// Assuming you have a Result<TSuccess, TError> type
using DotUnit;

public Result<Unit, string> SaveUser(User user)
{
    try
    {
        // Save user to database...
        return Result<Unit, string>.Success(Unit.Instance);
    }
    catch (Exception ex)
    {
        return Result<Unit, string>.Failure("Failed to save user.");
    }
}

License

This project is licensed under the MIT License.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  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.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.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.
  • .NETStandard 2.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0 109 7/14/2025

- add readonly record struct Unit