predicate

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2021 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Overview

Package predicate provides functions that wrap existing actions but executes them only on conditions ("predicates"). If a predicate evaluates to false, the wrapped action is not called and skips the step in the pipeline, indicating success.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func If added in v0.11.0

func If(predicate Predicate, originalStep pipeline.Step) pipeline.Step

If returns a new step that wraps the given step and executes its action only if the given Predicate evaluates true. The pipeline.Context from the pipeline is passed through the given action.

func ToNestedStep

func ToNestedStep(name string, predicate Predicate, p *pipeline.Pipeline) pipeline.Step

ToNestedStep wraps the given pipeline in its own step. When the step's function is called, the given Predicate will evaluate whether the nested pipeline.Pipeline should actually run. It returns the pipeline's pipeline.Result, otherwise an empty (successful) pipeline.Result struct. The given pipeline has to define its own pipeline.Context, it's not passed "down".

func ToStep

func ToStep(name string, action pipeline.ActionFunc, predicate Predicate) pipeline.Step

ToStep wraps the given action func in its own step. When the step's function is called, the given Predicate will evaluate whether the action should actually run. It returns the action's pipeline.Result, otherwise an empty (successful) pipeline.Result struct. The pipeline.Context from the pipeline is passed through the given action.

Types

type Predicate

type Predicate func(ctx pipeline.Context) bool

Predicate is a function that expects 'true' if a pipeline.ActionFunc should run. It is evaluated lazily resp. only when needed.

func And

func And(p1, p2 Predicate) Predicate

And returns a Predicate that does logical AND of the given predicates. p2 is not evaluated if p1 evaluates already to false.

func Bool

func Bool(v bool) Predicate

Bool returns a Predicate that simply returns v when evaluated. Use BoolPtr() over Bool() if the value can change between setting up the pipeline and evaluating the predicate.

func BoolPtr added in v0.12.0

func BoolPtr(v *bool) Predicate

BoolPtr returns a Predicate that returns *v when evaluated. Use BoolPtr() over Bool() if the value can change between setting up the pipeline and evaluating the predicate.

func Not

func Not(predicate Predicate) Predicate

Not returns a Predicate that evaluates, but then negates the given Predicate.

func Or

func Or(p1, p2 Predicate) Predicate

Or returns a Predicate that does logical OR of the given predicates. p2 is not evaluated if p1 evaluates already to true.

Jump to

Keyboard shortcuts

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