git clone ''

(ql:quickload :clojure.algo.generic)


Generic versions of commonly used functions, implemented as multimethods that can be implemented for any data type.


Each submodule of clojure.algo.generic defines a set of related multimethods that have the same names as their type-specific counterparts in clojure.core. Implementations for standard Clojure data types are provided and behave identically to the clojure.core versions.


Arithmetic and comparison functions are defined for the same arities that the corresponding clojure.core functions support. Arities higher than 2 are reduced to unary and binary calls. To provide a multimethod implementation for binary calls with a given pair of types, use [type1 type2] as the dispatch value. For a unary call, the dispatch value is type as usual. Note that [type1 type2] is different from [type2 type1] (in most cases you will want to provide both) and that [type type] (binary operation with both arguments of the same type) is different from type (unary operation).

Root type

This section applies only to binary operations dispatching on type pairs, and only for types that are not Java classes. Types created by deftype and defrecord are Java classes, meaning that most Clojure programmers can go on with the next section.

One difficulty with binary operations is that there is no predefined way to provide a default implementation. For single dispatch there is :default, but there is nothing equivalent to [:default :default]. The algo.generic library therefore defines a root type, accessible as clojure.algo.generic/root-type, which is used in the default implementations of binary operations. To integrate your own type into this system, you must add the clause (derive my-type clojure.algo.generic/root-type) after your type definition. This is not required for Java classes because java.lang.Object is already derived from root-type.


Releases and dependency information

Latest stable release: 0.1.3

Leiningen dependency information:

[org.clojure/algo.generic "0.1.3"]

Maven dependency information:



Copyright (c) Rich Hickey and contributors. All rights reserved.

The use and distribution terms for this software are covered by the Eclipse Public License 1.0 ( which can be found in the file epl.html at the root of this distribution. By using this software in any fashion, you are agreeing to be bound by the terms of this license. You must not remove this notice, or any other, from this software.