Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Action ¶
type Action[T comparable] struct { // The list of items to add to the current list. Adds []T // The list of items to delete from the current list. Deletes []T }
Action is results returned by Plan function. It contains the items to add to or delete from the current observed list to reach to the desired state.
func Plan ¶
func Plan[V comparable](desireds []V, currents []V) *Action[V]
Plan takes desired lists and current observed lists and decideds what action to take (which item to add to or delete from the current list) to reach to the given desired list. The results are returns as Action.
Example (Int) ¶
// The list of the item you desire to have. desireds := []int{1, 2, 3} // The list of the item currently you observes. currents := []int{1, 2, 4, 5} actions := Plan(desireds, currents) fmt.Printf("Add: %v, Delete: %v", actions.Adds, actions.Deletes)
Output: Add: [3], Delete: [4 5]
Example (String) ¶
// The list of the item you desire to have. desireds := []string{"alice", "bob", "charlie"} // The list of the item currently you observes. currents := []string{"alice", "bob", "dan", "frank"} actions := Plan(desireds, currents) fmt.Printf("Add: %v, Delete: %v", actions.Adds, actions.Deletes)
Output: Add: [charlie], Delete: [dan frank]
Click to show internal directories.
Click to hide internal directories.