https://github.com/lomin/spectree
This library for both Clojure and ClojureScript provides an 'each' selector to use in combination with specter and tree-like data structures. It also provides the macros '+>>' and 'each+>>' to chain specter transformations.
https://github.com/lomin/spectree
clojure clojurescript specter
Last synced: 5 months ago
JSON representation
This library for both Clojure and ClojureScript provides an 'each' selector to use in combination with specter and tree-like data structures. It also provides the macros '+>>' and 'each+>>' to chain specter transformations.
- Host: GitHub
- URL: https://github.com/lomin/spectree
- Owner: lomin
- License: epl-1.0
- Created: 2018-05-24T21:09:32.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-06-26T17:19:39.000Z (over 7 years ago)
- Last Synced: 2025-03-30T09:20:28.188Z (10 months ago)
- Topics: clojure, clojurescript, specter
- Language: Clojure
- Size: 12.7 KB
- Stars: 1
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# spectree
This library for both Clojure and ClojureScript provides an 'each' selector to use in combination with specter and tree-like data structures.
It also provides the macros '+>>' and 'each+>>' to chain specter transformations.
## Leiningen
*spectree* is available from Clojars. Add the following dependency to your *project.clj*:
[](https://clojars.org/me.lomin.spectree)
## Usage
```clojure
...
(require '[me.lomin.spectree.hiccup])
(deftest hiccup-test
(is (= ["bash" "top"]
(specter/select (spectree/each [:hiccup/CMD :hiccup/word 1])
[:PS
[:HEADER [:word "header"]]
[:LINE
[:UID [:number "501"]]
[:PID [:number "45427"]]
[:CMD [:word "bash"]]]
[:LINE
[:UID [:number "502"]]
[:PID [:number "45428"]]
[:CMD [:word "top"]]]]))))
(deftest generic-examples-test
(is (= {:a [:x [:c 2]] :e "add-if-not-here"}
(each+>> specter/transform
:hiccup/b (constantly :x)
:e (constantly "add-if-not-here")
:must/f (constantly "not-here")
{:a [[:b 1] [:c 2]]})))
(is (= {:a 6 :b 4}
(+>> specter/transform
[:a] inc
[:b] dec
{:a 5 :b 5})))
(is (= {:a 6 :b 4 :c {:d 6 :e 4 :f [0 2 2]}}
((+>> specter/transform
[:a] inc
[:c] (+>> specter/transform
[:d] inc
[:e] dec
[:f] (+>> specter/transform
1 inc))
[:b] dec)
{:a 5 :b 5 :c {:d 5 :e 5 :f [0 1 2]}}))))
```
## License
Copyright © 2018 Steven Collins
Distributed under the Eclipse Public License either version 1.0 or (at
your option) any later version.