Arc Forumnew | comments | leaders | submitlogin
'maptable
5 points by bd 6120 days ago | discuss
'maptable, like 'on (see http://arclanguage.org/item?id=5297), was bothering me. 'maptable runs a function of the key & value on the elements of a table, but doesn't return anything, like a new table with the function return values stored in it under the same keys. This function does that.

  (def maptable2 (f a)
    "Return a new table with f(k v) applied to each value"
    (let res (copy a)
      (ontable k v res
        (= (res k) (f k v)))))
Edit: I suppose this might be a little more elegant:

  (def maptable2 (f a)
    "Return a new table with f(k v) applied to each value"
    (w/table res
      (ontable k v a
        (= (res k) (f k v)))))