weaving
Weaving is to lambdas what threading is to s-expressions.
This library's purpose is to provide a set of simple function combinators to ease out the day-to-day wrangling of Clojure code.
Just like threading macros in Clojure end with an arrow, weaving functions end with |
.
Usage
[weaving "0.1.3"]
(require '[weaving.core :refer :all])
Showcase
(def f
(->| (when| number? (| * 2))
(if| (or| string? symbol?)
(|| str "The string ")
(->| str
(tap| (|| println "Warning: not a string:"))))
vector
(apply| (| clojure.string/replace "0" "X"))))
(f 100)
;; Warning: not a string: 200
;; => "2XX"
(f "slime")
;; => "The string slime"
API doc
List of combinators
- conditionals:
if|
,when|
,or|
,and|
¬|
. - partialization:
|
&||
. On the model of->
and->>
,-
(| str "ABC")
produces strings like"_ABC"
while -
(|| str "ABC")
produces strings like"ABC_"
.
-
- function arguments weaving:
•|
,-
((•| + identity (constantly 1)) 2)
yields3
.
-
- other control flow:
tap|
inspired by ruby. -
<-|
: works likeconstantly
. -
*|
: works likejuxt
. -
?|
:(?| 2)
is equivalent to#(= % 2)
. -
->|
: works likecomp
but in a reverse, sane order (the same as->
). -
apply|
.
License
Copyright © 2018 TristeFigure
Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version.