predicate

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2021 License: BSD-3-Clause Imports: 1 Imported by: 0

Documentation

Overview

Package predicate defines the interface between the asserter and specific predicates implementation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WrapError

func WrapError(nestedErr error, format string, a ...interface{}) error

WrapError appends the nested error after the formated message, on a new line

Types

type Func

type Func func(value interface{}) (Result, error)

Func is a the funcPredicate type that implements a predicate

type Result

type Result int8

Result that can be either failed, passed or invalid

const (
	// Invalid is the result of a predicate that could not be evaluated
	// and whom result is undetermined
	Invalid Result = iota

	// Failed is the result of a predicate evaluated successfully
	// yielding a negative result
	Failed

	// Passed is the result of a predicate evaluated successfully
	// yielding a positive result
	Passed
)

func (Result) String

func (r Result) String() string

func (Result) Success

func (r Result) Success() bool

Success is true for valid and positive results

func (Result) Valid

func (r Result) Valid() bool

Valid is true for successful evaluation yielding either positive or negative result

type T

type T interface {
	fmt.Stringer
	Evaluate(v interface{}) (Result, error)
}

T defines the minimum interface that predicates must implement

func Make

func Make(description string, fn Func) T

Make wraps a predicate funcPredicate into a predicate interface

func MakeBool

func MakeBool(
	description string,
	fn func(value interface{}) (bool, error)) T

MakeBool wraps a predicate funcPredicate returning bool into a predicate interface. Any error returned from the funcPredicate is interpreted as an invalid evaluation.

Jump to

Keyboard shortcuts

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