Documentation ¶
Overview ¶
Package Helpers provides a set of helper functions and types that can be used for automatic error handling and result evaluation.
However, this is still Work In Progress and is not yet fully implemented.
Index ¶
- func FilterNilHResult[T any](hr HResult[T]) bool
- type HResult
- func ApplyFunc[E, R any](elems []E, f uc.EvalOneFunc[E, R]) []HResult[R]
- func EvaluateFunc[E, R any](elem E, f uc.EvalOneFunc[E, R]) HResult[R]
- func EvaluateMany[E, R any](elem E, f uc.EvalManyFunc[E, R]) []HResult[R]
- func FilterOut[T any](batch []HResult[T]) []HResult[T]
- func FilterSuccessOrFail[T any](batch []HResult[T]) ([]HResult[T], bool)
- func NewHResult[T any](result T, reason error) HResult[T]
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FilterNilHResult ¶ added in v0.2.36
FilterNilHResult filters the HResult slice to remove nil values.
Parameters:
- hr: The HResult slice to filter.
Returns:
- bool: True if the HResult is not nil, false otherwise.
Types ¶
type HResult ¶
HResult is a generic type that represents the result of a function evaluation.
func ApplyFunc ¶ added in v0.2.39
func ApplyFunc[E, R any](elems []E, f uc.EvalOneFunc[E, R]) []HResult[R]
ApplyFunc applies a function to each element in the slice and returns the results as an array of HResults.
Parameters:
- elems: The slice to apply the function to.
- f: The function to apply.
Returns:
- []HResult: The results of the function application.
func EvaluateFunc ¶
func EvaluateFunc[E, R any](elem E, f uc.EvalOneFunc[E, R]) HResult[R]
EvaluateFunc evaluates a function and returns the result as an HResult.
Parameters:
- elem: The element to evaluate.
- f: The function to evaluate.
Returns:
- HResult: The result of the function evaluation.
func EvaluateMany ¶
func EvaluateMany[E, R any](elem E, f uc.EvalManyFunc[E, R]) []HResult[R]
EvaluateMany evaluates a function that returns multiple values and returns the results as an array of HResults.
Parameters:
- elem: The element to evaluate.
- f: The function to evaluate.
Returns:
- []HResult: The results of the function evaluation.
func FilterOut ¶
FilterOut removes all elements from the slice that have an error.
Parameters:
- batch: The slice to filter.
Returns:
- []HResult: The filtered slice.
func FilterSuccessOrFail ¶ added in v0.2.36
FilterSuccessOrFail filters the slice by returning only the successful results. However, if no successful results are found, it returns the original slice. The boolean indicates whether the slice was filtered or not.
Parameters:
- batch: The slice to filter.
Returns:
- []HResult: The filtered slice.
- bool: True if the slice was filtered, false otherwise.
func NewHResult ¶
NewHResult creates a new HResult with the given result and reason.
Parameters:
- result: The result of the function evaluation.
- reason: The error that occurred during the function evaluation.
Returns:
- HResult: The new HResult.
func (HResult[T]) DoIfFailure ¶ added in v0.2.36
func (hr HResult[T]) DoIfFailure(f uc.DualDoFunc[T, error])
DoIfFailure executes a function if the HResult is a failure.
Parameters:
- f: The function to execute.
func (HResult[T]) DoIfSuccess ¶ added in v0.2.36
DoIfSuccess executes a function if the HResult is successful.
Parameters:
- f: The function to execute.