Clojure

The update function: like update-in, for first level

Details

  • Type: Enhancement Enhancement
  • Status: Open Open
  • Priority: Minor Minor
  • Resolution: Unresolved
  • Affects Version/s: Release 1.6
  • Fix Version/s: Release 1.7
  • Component/s: None
  • Labels:
    None
  • Patch:
    Code and Test
  • Approval:
    Screened

Description

update-in is useful for updating nested structures. Very often we just want to update one level, so an update function optimised for this use case is useful.

It operates identically to update-in with a key path of length one so these are the same:

(update-in m [k] f args...)
(update m k f args...)

Patch: CLJ-1251.patch

Screened by: Alex Miller

  1. CLJ-1251.patch
    23/May/14 12:16 PM
    4 kB
    Ambrose Bonnaire-Sergeant
  2. update.patch
    03/Sep/13 9:01 AM
    2 kB
    Michael O. Church

Activity

Alex Miller made changes -
Field Original Value New Value
Labels enhancement
Rich Hickey made changes -
Approval Vetted [ 10003 ]
Fix Version/s Release 1.7 [ 10250 ]
Summary The update function: like update-in but allows multiple (shallow) updates at once. The update function: like update-in, for first level
Ambrose Bonnaire-Sergeant made changes -
Assignee Ambrose Bonnaire-Sergeant [ ambrosebs ]
Ambrose Bonnaire-Sergeant made changes -
Attachment update-like-update-in.patch [ 13003 ]
Ambrose Bonnaire-Sergeant made changes -
Description Like update-in, update allows functions to be applied to specified keys in an associative data structure. It does not support updates deeper than 1 level, and does not require a seq or vector of keys to be specified.

Unlike update-in, update allows multiple fields to be updated in one call, e.g.:

(def heal-spell [creature] (update creature :HP #(+ % 100) :MP #(- % 8) :spells-cast inc))

This is usually one of the first things I find myself adding to the language on my own projects, so I thought it'd be worth submitting. Apologies if this has already been discussed before.
`update-in` is useful for updating nested structures. Very often we just want to update one level, so an `update` function optimised for this use case is useful.

It operates identically to `update-in` with a key path of length one.

(update-in m [k] f args...)
=
(update m k f args...)
Alex Miller made changes -
Description `update-in` is useful for updating nested structures. Very often we just want to update one level, so an `update` function optimised for this use case is useful.

It operates identically to `update-in` with a key path of length one.

(update-in m [k] f args...)
=
(update m k f args...)
{{update-in}} is useful for updating nested structures. Very often we just want to update one level, so an {{update}} function optimised for this use case is useful.

It operates identically to {{update-in}} with a key path of length one so these are the same:

{code}
(update-in m [k] f args...)
(update m k f args...)
{code}

*Patch:* update-like-update-in.patch

*Screened by:*
Alex Miller made changes -
Approval Vetted [ 10003 ] Incomplete [ 10006 ]
Ambrose Bonnaire-Sergeant made changes -
Attachment update-like-update-in-2.patch [ 13009 ]
Alex Miller made changes -
Approval Incomplete [ 10006 ] Screened [ 10004 ]
Description {{update-in}} is useful for updating nested structures. Very often we just want to update one level, so an {{update}} function optimised for this use case is useful.

It operates identically to {{update-in}} with a key path of length one so these are the same:

{code}
(update-in m [k] f args...)
(update m k f args...)
{code}

*Patch:* update-like-update-in.patch

*Screened by:*
{{update-in}} is useful for updating nested structures. Very often we just want to update one level, so an {{update}} function optimised for this use case is useful.

It operates identically to {{update-in}} with a key path of length one so these are the same:

{code}
(update-in m [k] f args...)
(update m k f args...)
{code}

*Patch:* update-like-update-in-2.patch

*Screened by:* Alex Miller
Alex Miller made changes -
Approval Screened [ 10004 ] Incomplete [ 10006 ]
Ambrose Bonnaire-Sergeant made changes -
Attachment update-like-update-in-2.patch [ 13009 ]
Ambrose Bonnaire-Sergeant made changes -
Attachment update-like-update-in.patch [ 13003 ]
Ambrose Bonnaire-Sergeant made changes -
Attachment CLJ-1251.patch [ 13040 ]
Alex Miller made changes -
Approval Incomplete [ 10006 ] Vetted [ 10003 ]
Description {{update-in}} is useful for updating nested structures. Very often we just want to update one level, so an {{update}} function optimised for this use case is useful.

It operates identically to {{update-in}} with a key path of length one so these are the same:

{code}
(update-in m [k] f args...)
(update m k f args...)
{code}

*Patch:* update-like-update-in-2.patch

*Screened by:* Alex Miller
{{update-in}} is useful for updating nested structures. Very often we just want to update one level, so an {{update}} function optimised for this use case is useful.

It operates identically to {{update-in}} with a key path of length one so these are the same:

{code}
(update-in m [k] f args...)
(update m k f args...)
{code}

*Patch:* CLJ-1251.patch

*Screened by:*
Alex Miller made changes -
Approval Vetted [ 10003 ] Screened [ 10004 ]
Description {{update-in}} is useful for updating nested structures. Very often we just want to update one level, so an {{update}} function optimised for this use case is useful.

It operates identically to {{update-in}} with a key path of length one so these are the same:

{code}
(update-in m [k] f args...)
(update m k f args...)
{code}

*Patch:* CLJ-1251.patch

*Screened by:*
{{update-in}} is useful for updating nested structures. Very often we just want to update one level, so an {{update}} function optimised for this use case is useful.

It operates identically to {{update-in}} with a key path of length one so these are the same:

{code}
(update-in m [k] f args...)
(update m k f args...)
{code}

*Patch:* CLJ-1251.patch

*Screened by:* Alex Miller

People

Vote (3)
Watch (4)

Dates

  • Created:
    Updated: