Glossary
A functional pattern that runs multiple validations in parallel and collects all errors. Used with the Validation<Error, T> type.
(ValidateA(), ValidateB(), ValidateC()) .Apply((a, b, c) => new Result(a, b, c));Always Valid
Section titled “Always Valid”A pattern where a value object always maintains a valid state after creation. Created only after validation in a factory method.
The core operation of a monad. Passes the success value to another operation and short-circuits on failure. Equivalent to SelectMany.
result.Bind(value => NextOperation(value));ComparableValueObject
Section titled “ComparableValueObject”A value object that implements the IComparable<T> interface. Supports sorting and comparison operations.
CQRS (Command Query Responsibility Segregation)
Section titled “CQRS (Command Query Responsibility Segregation)”An architectural pattern that separates the responsibility of commands (writes) and queries (reads).
DDD (Domain-Driven Design)
Section titled “DDD (Domain-Driven Design)”A methodology for designing software centered around the domain model.
DomainError
Section titled “DomainError”A helper class that creates domain errors for value objects through the DomainError.For<T>() static method. Automatically generates error codes in the format DomainErrors.{ValueObjectName}.{ErrorName}.
using static Functorium.Domains.Errors.DomainErrorType;DomainError.For<Email>(new Empty(), value, "Email cannot be empty");DomainError.For<Password>(new TooShort(MinLength: 8), value, "Password too short");DomainErrorType
Section titled “DomainErrorType”The base record class for domain error types. Defines type-safe errors as a sealed record hierarchy. Built-in types: Empty, Null, TooShort, TooLong, WrongLength, OutOfRange, Negative, NotPositive, InvalidFormat, etc. Custom error types can be defined by deriving from the Custom record.
// Define a custom error typepublic sealed record Unsupported : DomainErrorType.Custom;Entity
Section titled “Entity”A domain object that has a unique identifier and can change during its lifecycle. The contrasting concept to a value object.
Error Type
Section titled “Error Type”The Error type from LanguageExt. Structured error information containing a code and a message.
Factory Method
Section titled “Factory Method”A static method that encapsulates object creation. In value objects, the Create method that includes validation.
A result type from LanguageExt. Represents Success (Succ) or Failure (Fail).
Fin<User> result = User.Create(name, email);Functor
Section titled “Functor”A type that supports the Map operation. Transforms the value inside a container.
GetEqualityComponents
Section titled “GetEqualityComponents”A method that returns the components used for equality comparison in a ValueObject.
protected override IEnumerable<object> GetEqualityComponents(){ yield return Property1; yield return Property2;}Immutability
Section titled “Immutability”The property that an object’s state cannot change after creation. A core principle of value objects.
IValueObject
Section titled “IValueObject”A marker interface indicating that something is a value object.
LanguageExt
Section titled “LanguageExt”A functional programming library for C#. Provides Fin<T>, Option<T>, Validation<E, T>, and more.
LINQ Expression
Section titled “LINQ Expression”Query syntax using from, select, where, etc. Can be combined with monad operations.
var result = from a in GetA() from b in GetB(a) select Combine(a, b);A transformation operation for functors/monads. Applies a function to the inner value and wraps the result in the same container.
Fin<int> number = 10;Fin<string> text = number.Map(n => n.ToString());Pattern matching. Executes different logic depending on the case such as success/failure, Some/None.
result.Match( Succ: value => HandleSuccess(value), Fail: error => HandleError(error));A type that supports the Bind operation. Supports both Map and Bind.
Option
Section titled “Option”A type that may or may not have a value. Used instead of null.
Option<User> user = Some(new User());Option<User> noUser = None;Operator Overloading
Section titled “Operator Overloading”Custom implementation of operators such as +, -, ==, implicit.
Prelude
Section titled “Prelude”A collection of static helper methods from LanguageExt. Used with using static LanguageExt.Prelude;.
Pure Function
Section titled “Pure Function”A function that always returns the same output for the same input without side effects.
Railway Oriented Programming
Section titled “Railway Oriented Programming”A functional error handling pattern that uses the analogy of railway tracks for success/failure paths.
Success path ─────────────────────────▶ ↘ ↘ Failure path ────▶────────▶───────────▶Sealed Class
Section titled “Sealed Class”A class that prohibits inheritance. Value objects are recommended to be declared as sealed.
Short-Circuit
Section titled “Short-Circuit”The behavior in a Bind chain where subsequent operations are skipped when a failure occurs.
SimpleValueObject
Section titled “SimpleValueObject”The base value object class that wraps a single value.
SmartEnum
Section titled “SmartEnum”An enumeration with behavior and properties. Based on the Ardalis.SmartEnum library.
Success-Driven Development
Section titled “Success-Driven Development”A methodology that develops around the success path using explicit result types instead of exceptions.
TypedValidation<TValueObject, T>
Section titled “TypedValidation<TValueObject, T>”The return type of ValidationRules<T>, a readonly struct that carries value object type information during validation chaining. Can be implicitly converted to Validation<Error, T>.
A type that represents no return value. Used instead of void to enable functional composition.
Fin<Unit> SaveData(data) => unit;Validation<Error, T>
Section titled “Validation<Error, T>”A type that supports parallel validation and error collection. Used with the Apply pattern.
ValidationRules
Section titled “ValidationRules”A static class that starts a validation chain by specifying the type parameter once. Provides start methods such as NotNull, NotEmpty, MinLength, MaxLength and chaining methods such as ThenNotEmpty, ThenMaxLength. The value object type name is automatically included in error codes.
ValidationRules<Email>.NotNull(value).ThenNotEmpty().ThenMaxLength(255)Value Equality
Section titled “Value Equality”Determining equality by value rather than by reference. Requires Equals and GetHashCode implementation.
Value Object
Section titled “Value Object”An immutable object defined solely by its values without an identifier. A core building block of DDD.
Characteristics:
- Immutability
- Value Equality
- Self-Validation
- Side-Effect Free
Next Steps
Section titled “Next Steps”Check the references.