A sum type for validating data in a functional programming style.
Represents two states: passing (Passing) with a value, or failing (Failing) with error messages.
Supports functor (map), monad (chain, of), and semigroup (concat) operations for declarative validation.
Designed for use with Redux Toolkit, Redux Observables, and React.
Type Param: T
The type of the data in Passing state.
Example
// Create a Validation for a passing value constpassing = Validation.Passing(42);
// Map the value constdoubled = passing.map(x=>x * 2); // Passing<84>
// Render in React with matchWith constrender = passing.matchWith({ Passing: ({ value }) => <p>Valid: {value}</p>, Failing: ({ messages }) => <p>Errors: {messages.join(', ')}</p>, });
A sum type for validating data in a functional programming style. Represents two states: passing (
Passing
) with a value, or failing (Failing
) with error messages. Supports functor (map
), monad (chain
,of
), and semigroup (concat
) operations for declarative validation. Designed for use with Redux Toolkit, Redux Observables, and React.Type Param: T
The type of the data in
Passing
state.Example