Bomret / Unit

A type that allows only one value, also known as void.

Home Page:http://bomret.github.io/Unit/index.html

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Nuget

CI Provider Status
Travis CI Travis CI
AppVeyor AppVeyor

Unit

The Unit type allows only one value which is empty. This is similar to the System.Void type (void keyword) which can sadly not be used by user code. Using the Unit type as return value instead of void offers some benefits, such as the deprecation of non-generic or special classes for the purpose of communicating the absence of a return value (Task<Unit> would replace Task, Func<Unit> et al. would make Action et al. obsolete).

Other languages, such as F#, Haskell or Scala already provide a Unit type, but Microsoft chose to prevent using the existing System.Void type in C# user code in favor of the void keyword.

Usage

Use Unit as return value instead of the void keyword.

// use
using TheVoid;

public Unit DoSomething() {
  //...
}

// instead of
public void DoSomething() {
  //...
}

To "return" Unit simply use one of the following

  • Unit.Default (recommended)
  • default(Unit)
  • new Unit()

Similar projects

  • @gregoryyoung created a similar type which he called Nothing but it missed some things.
  • @Reactive-Extensions the .net project contains a System.Unit type which is not available as a standalone package.

Planned deprecation

This project is deprecated as soon as any Unit type is included in C#.

Maintainer(s)

About

A type that allows only one value, also known as void.

http://bomret.github.io/Unit/index.html

License:The Unlicense


Languages

Language:F# 78.6%Language:C# 11.4%Language:Shell 7.0%Language:Batchfile 3.0%