DiscriminatedUnion<Type1, Type2> Class

Summary

A Discriminated union for 2 types.
Namespace
FunctionalSharp.DiscriminatedUnions
Base Types
  • object
graph TD Base0["object"]-->Type Type["DiscriminatedUnion<Type1, Type2>"] class Type type-node

Syntax

[Serializable]
public class DiscriminatedUnion<Type1, Type2>

Attributes

Type Description
SerializableAttribute

Type Parameters

Name Description
Type1 Type1
Type2 Type2

Constructors

Name Summary
DiscriminatedUnion() Private constructor to support serialization.
DiscriminatedUnion(object) Runs Actions for the matched types.
DiscriminatedUnion(Type1) Creates a new Discriminated union of with Type1
DiscriminatedUnion(Type2) Creates a new Discriminated union of with Type2

Fields

Name Constant Value Summary
Item1
The storage for type1.
Item2
The storage for type2.
tag
The tag indicating what item is actually stored.

Methods

Name Value Summary
Match(Action<Type1>, Action<Type2>) void
Runs Actions for the matched types.
Match<ReturnType>(Func<Type1, ReturnType>, Func<Type2, ReturnType>) ReturnType
Transforms the union into a new type using the given functions for the transformation.

Extension Methods

Name Value Summary
Match<DiscriminatedUnion<Type1, Type2>>() PatternMatchSingleContext<T>
Starts a pattern match for a single value. Subsequent calls to With() need to be used to specify conditions
ToOption<DiscriminatedUnion<Type1, Type2>>() IOption<T>
Turns the type T into an option type.