method

Value.WithListItem

Replace one list item while sharing unchanged immutable items.

Example

go
tags := store.List(store.String("news"), store.String("go"))
updated, ok := tags.WithListItem(0, store.String("updates"))
// tags still starts with "news".

Arguments

ArgumentTypeDescription
indexintThe zero-based position to replace.
replacementValueThe 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)

Source store/value.go:188

Related types

  • Value

    An immutable scalar, object, list, or populated document value.

Related guides