method
Value.WithListItem
Replace one list item while sharing unchanged immutable items.
Example
tags := store.List(store.String("news"), store.String("go"))
updated, ok := tags.WithListItem(0, store.String("updates"))
// tags still starts with "news".Arguments
| Argument | Type | Description |
|---|---|---|
index | int | The zero-based position to replace. |
replacement | Value | The replacement item. |
Returns
The updated list and true, or the original value and false for a non-list or an out-of-range index.
(Value, bool)How it works
The original list and retained snapshots are unchanged. Use List to change list length or order.
Full signature
func (value Value) WithListItem(
index int,
replacement Value,
) (Value, bool)Related types
ValueAn immutable scalar, object, list, or populated document value.