• Stars
    star
    102
  • Rank 335,584 (Top 7 %)
  • Language
    Clojure
  • License
    Eclipse Public Li...
  • Created almost 11 years ago
  • Updated about 5 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A library for composing lenses and working with complex state objects

Fresnel

A library for composing lenses and working with complex state objects. This library is a paired down version lens code embedded in Christophe Grand's Enliven.

Artifact

All artifacts are published to clojars.

Clojars Project

Note: Breaking changes in 0.3.0-SNAPSHOT

If you reified the Lens protocol directly you will have to now reify IFetch and IPutback protocols.

Concepts

The concept of a lens is very simple. A lens consists of two methods; one that transforms the state object into desired form and one that takes a transform object and pushes its state back into the main state object. Fresnel provides a mechanism to define lenses and to compose them. Fresnel builds on the concepts that already existing in Clojure. In Clojure we see two types of lenses for associative structures. The first is the keyword and we use get and assoc as the transform functions. The other is composition of these lenses in the form of a vector. We use get-in and assoc-in as transform functions in this case. Fresnel extends this concept beyond associative structures and unifies the access methods under a single protocol Lens.

(def state {:a {:aa "a1,b1,c1"
                :ab 2}
            :b {:ba "a2,b2,c2"
                :bb 2}})

;fresnel supports custom lenses
(deflens comma-to-map [oval nval]
  :fetch 
    (reduce #(assoc %1 (.trim %2) true) {} (split oval #","))
  :putback
    (reduce #(if %1 (str %2 "," %1) %2)
            nil
            (filter #(nval %1) (keys nval))))

;fresnel supports composing of lenses
(def compound-lens [:a :aa comma-to-map])

(fetch state compound-lens)
;{:a1 true :b1 true :c1 true}

(def new-state 
   (putback state 
            compound-lens 
            {:a1 false :b1 true :c1 true :d1 true}))

;;new-state {:a {:aa "b1,c1,d1" :ab 2}
;;           :b {:ba "a2,b2,c2" :bb 2}})     

License

Copyright Β© 2014 Creighton Kirkendall

Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version.

More Repositories

1

kioo

Enlive/Enfocus style templating for Facebook's React and Om in ClojureScript.
Clojure
403
star
2

enfocus

DOM manipulation and templating library for ClojureScript inspired by Enlive.
Clojure
370
star
3

ziad

Part of speech tagger/grammer checker written in clojure
Clojure
22
star
4

The-Great-Todo

Sample service-driven web application using Clojure, ClojureScript, Monger, Enfocus, Noir, and Fetch. Created for CinJug April 2012 Presentation.
Clojure
20
star
5

ClojureGiven

An BDD test framework for Clojure inspired by Jim Weirich's ruby based rspec-given
Clojure
19
star
6

enfocus-charts

Begining stages of a ClojureScript charting library based on Google Closure Graphics APIs.
Clojure
13
star
7

peli

Simple 2D game engine in ClojureScript for mario like games
Clojure
11
star
8

enfocus-demo-site

This is the source for the demo and documentation site for enfocus
HTML
10
star
9

cljs-prezo

ClojureScript intro presentation and sample application
JavaScript
7
star
10

chatter-box

Demo application for core.async and Enfocus
JavaScript
4
star
11

sample-face-track

Simple python client to face tract for usb camera and pi camera
Python
4
star
12

midje-cljs-playground

Playground for ideas relating to porting Midje to ClojureScript
Clojure
3
star
13

enfocus-site

Static website for enfocus hosted through ghpages
HTML
3
star
14

genus

Very basic bayesian classifier
Clojure
3
star
15

MLisp

Minimum Lisp Implementation in Scala create for CincyFP presentation
Scala
3
star
16

ClojureScript-DOM-Examples

These are two examples apps developed to show the different approaches Dommy and Enfocus take towards DOM manipulation and templating.
CSS
3
star
17

Presentations

static versions of my presentations
JavaScript
2
star
18

fyke

Book visualizer based on hyper dimensional word vectors.
Clojure
2
star
19

haskell-lisp-tutorial

This is a step by step tutorial on building a lisp in haskell
Haskell
1
star
20

CKLisp

A lisp interpreter for the jvm, complete with macros, TCO and java interop, written in about 400 lines of Scala code
Scala
1
star
21

cinjug-sept-2011

Presentation for CinJug
JavaScript
1
star
22

enfocus-template

Leiningen template for a ClojureScript app based on Enfocus and Ring
Clojure
1
star
23

hlisp

Little lisp written in haskell
Haskell
1
star