Helpers

package
v0.2.43 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 19, 2024 License: MIT Imports: 3 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func FilterNilHResult added in v0.2.36

func FilterNilHResult[T any](hr HResult[T]) bool

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

type HResult[T any] cdp.Pair[T, error]

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

func FilterOut[T any](batch []HResult[T]) []HResult[T]

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

func FilterSuccessOrFail[T any](batch []HResult[T]) ([]HResult[T], bool)

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

func NewHResult[T any](result T, reason error) HResult[T]

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

func (hr HResult[T]) DoIfSuccess(f uc.DoFunc[T])

DoIfSuccess executes a function if the HResult is successful.

Parameters:

  • f: The function to execute.

func (HResult[T]) IsSuccess added in v0.2.36

func (hr HResult[T]) IsSuccess() bool

IsSuccess checks if the HResult is successful.

Returns:

  • bool: True if the HResult is successful, false otherwise.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL