Mercurial > lasercutter
view src/clojure/contrib/fnmap.clj @ 10:ef7dbbd6452c
added clojure source goodness
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Sat, 21 Aug 2010 06:25:44 -0400 |
parents | |
children |
line wrap: on
line source
1 ;;; fnmap.clj: maps that dispatch get/assoc to functions3 ;; Copyright (c) Stuart Sierra, 2008. All rights reserved. The use4 ;; and distribution terms for this software are covered by the Eclipse5 ;; 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 this7 ;; distribution. By using this software in any fashion, you are8 ;; agreeing to be bound by the terms of this license. You must not9 ;; remove this notice, or any other, from this software.12 (ns ^{:author "Stuart Sierra"13 :doc "Maps that dispatch get/assoc to user-defined functions.15 Note: requires AOT-compilation"}16 clojure.contrib.fnmap17 (:require clojure.contrib.fnmap.PersistentFnMap))19 (defn fnmap20 "Creates a fnmap, or functional map. A fnmap behaves like an21 ordinary Clojure map, except that calls to get and assoc are22 filtered through user-defined getter and setter functions, which23 operate on an internal map.25 (getter m key) should return a value for key.27 (setter m key value) should assoc key with value and return a new28 map for m.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 assoc34 (clojure.contrib.fnmap.PersistentFnMap/create getter setter)35 keyvals)))