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.
:updatereturns 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
Dave
Dave
Related Variants
Goblin provides several targeted forms of update:
- update_all
- update_at
- update_between
- update_first
- update_last
- update_matching
- update_random
- update_where