collections

package
v0.27.0 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2024 License: MPL-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package collections provides utilities for working with collections inside of plan

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CompareActions

func CompareActions(current, next action.Action) action.Action

CompareActions will compare current and next, and return plans.Update if they are different, and current if they are the same.

func LongestCommonSubsequence

func LongestCommonSubsequence[V any](xs, ys []V, equals func(x, y V) bool) ([]V, error)

LongestCommonSubsequence finds a sequence of values that are common to both x and y, with the same relative ordering as in both collections. This result is useful as a first step towards computing a diff showing added/removed elements in a sequence.

The approached used here is a "naive" one, assuming that both xs and ys will generally be small in most reasonable Terraform configurations. For larger lists the time/space usage may be sub-optimal.

A pair of lists may have multiple longest common subsequences. In that case, the one selected by this function is undefined.

func ProcessSlice

func ProcessSlice[Input any](before, after []Input, process ProcessIndices, isObjType IsObjType[Input]) error

ProcessSlice will process each element in the before and after slices

func TransformMap

func TransformMap[Input any](before, after map[string]Input, keys []string, process ProcessKey) (map[string]computed.Diff, action.Action, error)

TransformMap transforms an input map into a computed.Diff and a action.Action

func TransformSlice

func TransformSlice[Input any](before, after []Input, process TransformIndices, isObjType IsObjType[Input]) ([]computed.Diff, action.Action, error)

TransformSlice transforms a pair of slices into a computed.Diff and a action.Action

Types

type IsObjType

type IsObjType[Input any] func(input Input) (bool, error)

IsObjType is a callback function that returns true if the input is an object type

type ProcessIndices

type ProcessIndices func(before, after int) error

ProcessIndices is a callback function that processes a pair of indices

type ProcessKey

type ProcessKey func(key string) (computed.Diff, error)

ProcessKey is a callback function that processes a key

type TransformIndices

type TransformIndices func(before, after int) (computed.Diff, error)

TransformIndices is a callback function that transforms a pair of indices

Jump to

Keyboard shortcuts

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