Clojure

The update function: like update-in but allows multiple (shallow) updates at once.

Details

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

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.

Activity

People

Vote (0)
Watch (1)

Dates

  • Created:
    Updated: