do_what_now library
Support for a functional approach to error handling.
One can return an instance of a DoWhat from any method and return either an What or a value. Values returned are defined by the Generic
DoWhats can also be created from any Object instance using the static create method. Null objects will return an What result while valid objects will return a DoWhat containing the valid Object of
Once a DoWhat is created a fluent API using extension methods can be leverage to handle the 'Do' (happy path) or 'What' (error path).
Classes
-
DoWhat<
TValue> - The DoWhat type is the result of a method an object or method. Results can contain either a List<> of What or value of the specified type
-
What<
TError> - Defines an error or issue that cause a DoWhat to return a failure. The error class can be implemented or extended to provide custom error type or
-
WhatEmpty<
TValue> - WhatEmpty provides a default error to handle NULL refernces.
- WhatException
- WhatException stores an exception provided to the DoWhat
- WhatMessage
- WhatMessage stores a custom string provided to the DoWhat
- WhatObject
- WhatObject stores a custom object provided to the DoWhat
Enums
Extensions
-
ResultExtensions
on DoWhat<
TValue> - Extension methods designed to provide a fluent API These methods allow users to safely chain together DoWhats and safely continue on either the happy path or the sad path.
-
WhatErrorsExtension
on List<
What> - Extension methods used to work with collections of What objects.
Functions
-
combine<
T1, T2> (DoWhat< T1> result1, DoWhat<T2> result2) → DoWhat<(T1, T2)> - Returns a tuple result.
-
create<
TValue> (TValue value) → DoWhat< TValue> -
Factory method to create a new result DoWhat from an instance of an object
The create method will return a successful result only if the
TValue
is NOT null -
empty<
T> () → WhatEmpty -
Creates a new WhatEmpty extending What of the Type
T
Returns a formmatted message describing the instance ofT
-
exception(
Exception ex) → WhatException - Creates a new WhatException extending What of the Type Exception Returns a formmatted message describing the instance of Exception
-
failure<
TValue> (What error) → DoWhat< TValue> - Factory method to create a new failed DoWhat
-
failures<
TValue> (List< What> errors) → DoWhat<TValue> - Factory method to create a new failed DoWhat with several errors
-
from<
TValue> (TValue value, bool predicate(TValue value), {String? message}) → DoWhat< TValue> - Factory method to create a new DoWhat The from method will evaluate the value and execute the predicate. The DoWhat will be successfull if the callers predicate returns true.
-
message(
String message) → WhatMessage - Creates a new WhatMessage extending What Returns a formmatted message describing the error
-
success<
TValue> (TValue value) → DoWhat< TValue> - Factory method to create a new Successful DoWhat
-
what(
Object obj) → WhatObject - Creates a new WhatObject extending What Returns a formmatted message describing the instance of the Object