Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 37 lines (27 sloc) 1.404 kB
016af1d @stuartsierra fnmap.clj: added new library; maps with custom implementations
stuartsierra authored
1 ;;; fnmap.clj: maps that dispatch get/assoc to functions
2
3 ;; Copyright (c) Stuart Sierra, 2008. All rights reserved. The use
4 ;; and distribution terms for this software are covered by the Eclipse
5 ;; Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
6 ;; which can be found in the file epl-v10.html at the root of this
7 ;; distribution. By using this software in any fashion, you are
8 ;; agreeing to be bound by the terms of this license. You must not
9 ;; remove this notice, or any other, from this software.
10
11
12 (ns #^{:author "Stuart Sierra"
13 :doc "Maps that dispatch get/assoc to user-defined functions.
14
15 Note: requires AOT-compilation"}
16 clojure.contrib.fnmap
17 (:require clojure.contrib.fnmap.PersistentFnMap))
18
19 (defn fnmap
20 "Creates a fnmap, or functional map. A fnmap behaves like an
21 ordinary Clojure map, except that calls to get and assoc are
22 filtered through user-defined getter and setter functions, which
23 operate on an internal map.
24
25 (getter m key) should return a value for key.
26
27 (setter m key value) should assoc key with value and return a new
28 map for m.
29
30 All other map operations are passed through to the internal map."
31 ([getter setter] (clojure.contrib.fnmap.PersistentFnMap/create getter setter))
32 ([getter setter & keyvals]
33 (apply assoc
34 (clojure.contrib.fnmap.PersistentFnMap/create getter setter)
35 keyvals)))
36
Something went wrong with that request. Please try again.