-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
39 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,16 +9,19 @@ A simple Lens library for Carp. | |
```clojure | ||
(load "[email protected]:hellerve/lens.carp@master") | ||
|
||
(deftype Address [city String street (Pair String Int)]) | ||
(deftype Address [ | ||
city String | ||
street (Pair String Int)] | ||
) | ||
|
||
(defn main [] | ||
(let-do [addr (Lens.for Address street) | ||
stre (Lens.for Pair a) | ||
comp (Lens.compose &addr &stre) | ||
data (Address.init @"Berlin" (Street.init 10 @"Paul-Lincke-Ufer"))] | ||
(println* &(~(Lens.get &comp) &data)) | ||
(println* &(~(Lens.set &comp) @&data @"no")) | ||
(println* &(Lens.over &comp @&data &(fn [a] (reverse &a)))) | ||
data (Address.init @"Berlin" (Pair.init @"Paul-Lincke-Ufer" 10))] | ||
(IO.println &(str (Lens.get &comp &data))) | ||
(IO.println &(str &(Lens.set &comp &data @"Maybachufer"))) | ||
(IO.println &(str &(Lens.update &comp &data &reverse))) | ||
) | ||
) | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,17 @@ | ||
(load "lens.carp") | ||
|
||
(deftype Address [city String street (Pair String Int)]) | ||
(deftype Address [ | ||
city String | ||
street (Pair String Int)] | ||
) | ||
|
||
(defn main [] | ||
(let-do [addr (Lens.for Address street) | ||
stre (Lens.for Pair a) | ||
comp (Lens.compose &addr &stre) | ||
data (Address.init @"Berlin" (Pair.init @"Paul-Lincke-Ufer" 10))] | ||
(println* &(~(Lens.get &comp) &data)) | ||
(println* &(~(Lens.set &comp) @&data @"no")) | ||
(println* &(Lens.over &comp @&data &(fn [a] (reverse &a)))) | ||
(IO.println &(str (Lens.get &comp &data))) | ||
(IO.println &(str &(Lens.set &comp &data @"Maybachufer"))) | ||
(IO.println &(str &(Lens.update &comp &data &reverse))) | ||
) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters