Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/randomcorp/thread-first-thread-last-backwards-question-mark-as-arrow-cond-arrow-bang
The exciting new ->->><?as->cond->! macro
https://github.com/randomcorp/thread-first-thread-last-backwards-question-mark-as-arrow-cond-arrow-bang
Last synced: 27 days ago
JSON representation
The exciting new ->->><?as->cond->! macro
- Host: GitHub
- URL: https://github.com/randomcorp/thread-first-thread-last-backwards-question-mark-as-arrow-cond-arrow-bang
- Owner: randomcorp
- Created: 2018-11-25T05:04:38.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2020-04-02T11:53:53.000Z (over 4 years ago)
- Last Synced: 2024-08-03T13:04:46.729Z (4 months ago)
- Language: Clojure
- Size: 4.88 KB
- Stars: 524
- Watchers: 11
- Forks: 5
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- stars - randomcorp/thread-first-thread-last-backwards-question-mark-as-arrow-cond-arrow-bang - The exciting new ->->><?as->cond->! macro (⭐️523) (Clojure)
- stars - randomcorp/thread-first-thread-last-backwards-question-mark-as-arrow-cond-arrow-bang - The exciting new ->->><?as->cond->! macro (⭐️523) (Clojure)
README
# ->->>cond->!
_As seen in [Every Clojure Talk Ever](https://www.youtube.com/watch?v=jlPaby7suOc) by [Amperity](https://github.com/amperity)_
This is the bread and butter of randomcorp's Clojure code and we're
excited to share it with the world. Have you been frustrated with
always needing to compose the various types of threading macros?```clojure
(-> []
(conj 1 2 3)
(->> (mapv inc))
(as-> v
{:vec-of-numbers v})
(cond->
(some-pred) (assoc :other-key "other-val")))
```It would be nice if there were one single macro to do all that for
you. Well, now there is!```clojure
(->->>cond->!
[]
:-> (conj 1 2 3)
:->> (mapv inc)
:as-> v {:vec-of-numbers v}
:cond-> (some-pred) (assoc :other-key "other-val"))
```To short-circuit on nil values (a la `some->`), use `:`:
```clojure
(->->>cond->!
[]
:-> not-empty
:
:-> (conj 1));; => nil
```To make assertions about the values during the threading, use `:!`:
```clojure
(->->>cond->!
2
:-> inc
:! even?);; => Error!
```## License
Free, as in beer.