plan

package
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2024 License: BSD-3-Clause Imports: 2 Imported by: 0

Documentation

Overview

Package plan provides an efficient mechanism for updating a slice to contain a target list of elements, generating minimal edits to modify the current slice contents to match the target. The mechanism depends on the use of unique name string identifiers to determine whether an element is currently configured correctly. These could be algorithmically generated hash strings or any other such unique identifier.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Update

func Update[T Namer](s *[]T, n int, name func(i int) string, new func(name string, i int) T, init func(e T, i int), destroy func(e T)) bool

Update ensures that the elements of the given slice contain the elements according to the plan specified by the given arguments. The argument n specifies the total number of items in the target plan. The elements have unique names specified by the given name function. If a new item is needed, the given new function is called to create it for the given name at the given index position. After a new element is created, it is added to the slice, and if the given optional init function is non-nil, it is called with the new element and its index. If the given destroy function is not-nil, then it is called on any element that is being deleted from the slice. Update returns whether any changes were made. The given slice must be a pointer so that it can be modified live, which is required for init functions to run when the slice is correctly updated to the current state.

Types

type Namer

type Namer interface {

	// PlanName returns the name of the object in a plan context.
	PlanName() string
}

Namer is an interface that types can implement to specify their name in a plan context.

Jump to

Keyboard shortcuts

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