Mercurial > lasercutter
view src/clojure/contrib/fnmap/PersistentFnMap.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 ;; PersistentFnMap.clj: implementation for clojure.contrib.fnmap3 ;; Copyright (c) Stuart Sierra, 2009. 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 ;; Thanks to Meikel Brandmeyer for his work on lazymap, which made13 ;; this implementation easier.16 (ns clojure.contrib.fnmap.PersistentFnMap17 (:gen-class :extends clojure.lang.APersistentMap18 :state state19 :init init20 :constructors {[clojure.lang.IPersistentMap] [],21 [clojure.lang.IPersistentMap clojure.lang.IPersistentMap] [clojure.lang.IPersistentMap]}))23 (defn -init24 ([theMap] [[] theMap])25 ([theMap metadata] [[metadata] theMap]))27 (defn create [getter setter]28 (clojure.contrib.fnmap.PersistentFnMap.29 {::getter getter ::setter setter}))31 ;; IPersistentMap33 (defn -assoc [this key value]34 (clojure.contrib.fnmap.PersistentFnMap.35 ((::setter (. this state)) (. this state) key value)))37 ;; Associative39 (defn- -containsKey [this key]40 (not (nil? ((::getter (. this state)) this key))))42 (defn- -entryAt [this key]43 (clojure.lang.MapEntry. key ((::getter (. this state)) (. this state) key)))45 (defn -valAt46 ([this key]47 ((::getter (. this state)) (. this state) key))48 ([this key default]49 (or ((::getter (. this state)) (. this state) key)50 default)))52 ;; Iterable54 (defn -iterator [this]55 (.. this state iterator))57 ;; IPersistentCollection59 (defn -count [this]60 (count (. this state)))62 (defn -seq [this]63 (seq (. this state)))65 (defn -cons [this that]66 (.. this state (cons this that)))68 (defn -empty [this]69 (.. this state empty))