Helpers

package
v0.2.32 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2024 License: MIT Imports: 0 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 FilterOut

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

FilterOut removes all elements from the slice that have an error.

Parameters:

  • batch: The slice to filter.

Types

type EvalFunc added in v0.2.32

type EvalFunc[T any] func() (T, error)

EvalFunc is a generic type that represents a function that returns a value and an error.

Returns:

  • T: The result of the function evaluation.
  • error: The error that occurred during the function evaluation.

type EvalManyFunc added in v0.2.32

type EvalManyFunc[T any] func() ([]T, error)

EvalManyFunc is a generic type that represents a function that returns multiple values and an error.

Returns:

  • []T: The result of the function evaluation.
  • error: The error that occurred during the function evaluation.

type HResult

type HResult[T any] struct {
	// Result is the result of the function evaluation.
	Result T

	// Reason is the error that occurred during the function evaluation.
	Reason error
}

HResult is a generic type that represents the result of a function evaluation.

func EvaluateFunc

func EvaluateFunc[T any](f EvalFunc[T]) HResult[T]

EvaluateFunc evaluates a function and returns the result as an HResult.

Parameters:

  • f: The function to evaluate.

Returns:

  • HResult: The result of the function evaluation.

func EvaluateMany

func EvaluateMany[T any](f EvalManyFunc[T]) []HResult[T]

EvaluateMany evaluates a function that returns multiple values and returns the results as an array of HResults.

Parameters:

  • f: The function to evaluate.

Returns:

  • []HResult: The results of the function evaluation.

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.

Jump to

Keyboard shortcuts

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