Enum Unit
Represents a unit type.
Namespace: Maki
Assembly: Maki.dll
Syntax
public enum Unit
Examples
A unit type has only one possible value. It is semantically equivalent tovoid
, but
can be instantiated. Optional<T>
uses Unit
to represent the absence of
a value.
using Maki;
using System;
namespace Samples
{
class Program
{
// Assume a generic library method which expects a Func<int, T> and applies
// it to 42
static T Apply<T>(Func<int, T> func)
{
return func(42);
}
static void Main(string[] args)
{
// If the return type is not meaningful, we would use void but we
// cannot create a Func<int, void> since cannot be used as a generic
// argument. We can return Unit instead.
Func<int, Unit> func = i => Unit.Singleton;
Apply(func);
}
}
}
Fields
Name | Description |
---|---|
Singleton | Unique value. |