Skip to content

Instantly share code, notes, and snippets.

View ck's full-sized avatar
💭
I may be slow to respond.

ck ck

💭
I may be slow to respond.
  • United States
  • 14:45 (UTC -04:00)
View GitHub Profile
@ck
ck / test.clj
Created June 25, 2013 11:54 — forked from adambard/test.clj
; Comments start with semicolons.
; Clojure is written in "forms", which are just
; lists of things inside parentheses, separated by whitespace.
;
; The clojure reader assumes that the first thing is a
; function or macro to call, and the rest are arguments.
;
; Here's a function that sets the current namespace:
(ns test)
@ck
ck / lenses.clj
Created December 29, 2020 21:56 — forked from ctford/lenses.clj
A Clojure lens implementation based on focus and fmap.
(ns shades.lenses)
; We only need three fns that know the structure of a lens.
(defn lens [focus fmap] {:focus focus :fmap fmap})
(defn view [x {:keys [focus]}] (focus x))
(defn update [x {:keys [fmap]} f] (fmap f x))
; The identity lens.
(defn fapply [f x] (f x))
(def id (lens identity fapply))