Mercurial > lasercutter
view src/clojure/contrib/generic/functor.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 ;; Generic interface for functors3 ;; by Konrad Hinsen4 ;; last updated May 3, 20096 ;; Copyright (c) Konrad Hinsen, 2009. All rights reserved. The use7 ;; and distribution terms for this software are covered by the Eclipse8 ;; Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)9 ;; which can be found in the file epl-v10.html at the root of this10 ;; distribution. By using this software in any fashion, you are11 ;; agreeing to be bound by the terms of this license. You must not12 ;; remove this notice, or any other, from this software.14 (ns15 ^{:author "Konrad Hinsen"16 :doc "Generic functor interface (fmap)"}17 clojure.contrib.generic.functor)20 (defmulti fmap21 "Applies function f to each item in the data structure s and returns22 a structure of the same kind."23 {:arglists '([f s])}24 (fn [f s] (type s)))26 (defmethod fmap clojure.lang.IPersistentList27 [f v]28 (into (empty v) (map f v)))30 (defmethod fmap clojure.lang.IPersistentVector31 [f v]32 (into (empty v) (map f v)))34 (defmethod fmap clojure.lang.IPersistentMap35 [f m]36 (into (empty m) (for [[k v] m] [k (f v)])))38 (defmethod fmap clojure.lang.IPersistentSet39 [f s]40 (into (empty s) (map f s)))