ddonche/goblin-lang
0.46.24
1
0
docs reference
[[update]]

Update


Update replaces values in a collection.


Overview

update replaces values inside a collection.

items | [1, 2, 3]

:update!(items, [9, 9, 9])
items | [1, 2, 3]

:update!(items, [9, 9, 9])

Result:

[9, 9, 9]
[9, 9, 9]


Mutation

Like most collection utilities, update follows Goblin's bang (!) rules.

  • :update returns a modified copy
  • :update! mutates the original collection

items | [1, 2, 3]

:update(items, [9, 9, 9])
items | [1, 2, 3]

:update(items, [9, 9, 9])

The original collection remains unchanged.

:update!(items, [9, 9, 9])
:update!(items, [9, 9, 9])

The original collection is modified.


Update Operator

The |! operator is shorthand for :update!.

name | "Daniel"

name |! "Dave"
name | "Daniel"

name |! "Dave"

Tip
This also works with update_at! but you'll need to see how it's done—it's slightly different. See update_at.

Equivalent to:

:update!(name, "Dave")
:update!(name, "Dave")

Result:
Dave
Dave

Related Variants

Goblin provides several targeted forms of update: