Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 41 lines (31 sloc) 1.187 kb
334ad56 generic: new module functor
Konrad Hinsen authored
1 ;; Generic interface for functors
2
3 ;; by Konrad Hinsen
bdc813a Namespace documentation for autodoc
Konrad Hinsen authored
4 ;; last updated May 3, 2009
334ad56 generic: new module functor
Konrad Hinsen authored
5
6 ;; Copyright (c) Konrad Hinsen, 2009. All rights reserved. The use
7 ;; and distribution terms for this software are covered by the Eclipse
8 ;; 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 this
10 ;; distribution. By using this software in any fashion, you are
11 ;; agreeing to be bound by the terms of this license. You must not
12 ;; remove this notice, or any other, from this software.
13
bdc813a Namespace documentation for autodoc
Konrad Hinsen authored
14 (ns
b8d2743 use the 1.2 metadata reader macro ^ instead of #^
Aaron Bedra and Stuart Halloway authored
15 ^{:author "Konrad Hinsen"
bdc813a Namespace documentation for autodoc
Konrad Hinsen authored
16 :doc "Generic functor interface (fmap)"}
17 clojure.contrib.generic.functor)
334ad56 generic: new module functor
Konrad Hinsen authored
18
19
20 (defmulti fmap
21 "Applies function f to each item in the data structure s and returns
22 a structure of the same kind."
23 {:arglists '([f s])}
24 (fn [f s] (type s)))
25
22fe339 generic.functor: implementation for lists replaces implementation for se...
Konrad Hinsen authored
26 (defmethod fmap clojure.lang.IPersistentList
27 [f v]
28 (into (empty v) (map f v)))
334ad56 generic: new module functor
Konrad Hinsen authored
29
30 (defmethod fmap clojure.lang.IPersistentVector
31 [f v]
32 (into (empty v) (map f v)))
33
34 (defmethod fmap clojure.lang.IPersistentMap
35 [f m]
36 (into (empty m) (for [[k v] m] [k (f v)])))
37
38 (defmethod fmap clojure.lang.IPersistentSet
39 [f s]
40 (into (empty s) (map f s)))
Something went wrong with that request. Please try again.