Mercurial > cortex
diff org/util.org @ 26:bbffa41a12a9
moved apply-map to util.org from world.org, fixed some grammar problems, made examples more concise
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Mon, 24 Oct 2011 05:41:50 -0700 |
parents | 775d97247dd0 |
children | 122f12f81dc1 |
line wrap: on
line diff
1.1 --- a/org/util.org Mon Oct 24 05:25:01 2011 -0700 1.2 +++ b/org/util.org Mon Oct 24 05:41:50 2011 -0700 1.3 @@ -217,6 +217,16 @@ 1.4 (add-element game element (.getRootNode game)))) 1.5 1.6 1.7 +(defn apply-map 1.8 + "Like apply, but works for maps and functions that expect an 1.9 + implicit map and nothing else as in (fn [& {}]). 1.10 + ------- Example ------- 1.11 + (defn demo [& {:keys [www] :or {www \"oh yeah\"} :as env}] 1.12 + (println www)) 1.13 + (apply-map demo {:www \"hello!\"}) 1.14 + -->\"hello\"" 1.15 + [fn m] 1.16 + (apply fn (reduce #(into %1 %2) [] m))) 1.17 1.18 #+end_src 1.19