Liking cljdoc? Tell your friends :D


A lenses library in Clojure.


Sometimes you find yourself doing plenty of get-ins, update-ins or assoc-ins, and you happen to care about performance.

If you know the keys in advance everything is good and you can use clj-fast. But what happens if you don't, but the keys which you'll work with rarely change?

If you knew the keys, that's usually where you'll create the fn object in advance and cache it. But figuring out how many keys you need to work with isn't so expensive, and the added benefit of faster calculations offsets the one time cost of analyzing the keys.

This is where lenses come in. Lenses are objects which satisfy a simple interface:

lens interfaceClojure equivalent

Since the library is built on top of clj-fast, these perform well enough to justify caching over walking over keys dynamically.


Require Adashot

(require '[adashot.core :as a])


(ns my-ns
  (:require [adashot.core :as a]))

Create a lens

(def ks [:a :b])
(def lens (a/keys->fast-lens ks))

Use a lens

(def m {:a {:b 1}})
(a/view lens m)
(a/put lens m 2)
(a/over lens m + 2 3)


Copyright © 2020 Ben Sless

This program and the accompanying materials are made available under the terms of the Eclipse Public License 2.0 which is available at

This Source Code may also be made available under the following Secondary Licenses when the conditions for such availability set forth in the Eclipse Public License, v. 2.0 are satisfied: GNU General Public License as published by the Free Software Foundation, either version 2 of the License, or (at your option) any later version, with the GNU Classpath Exception which is available at

Can you improve this documentation?Edit on GitHub

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close