A library containing macros for use in clojure threading expressions (using ->).
See reference documentation and annotated source.
Threaded arg exposure:
arg-> exposes the threaded arg, binding it to the supplied variable. For example:
(-> 2
(arg-> [x]
(* (inc x))))
;=> 6Expands to:
(-> 2
((fn [arg] (let [x arg] (-> arg (* inc x))))))
;=> 6Note the extra set of parens in the expansion; the threading macro feeds the current argument in as arg, binds it to the supplied var using let, and resumes threading for all forms inside of arg->.
Threaded list comprehension:
The following use of for->:
(-> 1
(for-> [x [1 2 3]]
(+ x)))
;=> 7Expands to:
(-> 1
(+ 1)
(+ 2)
(+ 3))
;=> 7thread-expr is distributed as a jar, and is available in the sonatype repository.
Installation is with maven or your favourite maven repository aware build tool.
:dependencies [[org.cloudhoist/thread-expr "1.1.0"]]
:repositories {"sonatype"
"http://oss.sonatype.org/content/repositories/releases"}
<dependencies>
<dependency>
<groupId>org.cloudhoist</groupId>
<artifactId>thread-expr</artifactId>
<version>1.1.0</version>
</dependency>
<dependencies>
<repositories>
<repository>
<id>sonatype</id>
<url>http://oss.sonatype.org/content/repositories/releases</url>
</repository>
</repositories>
Licensed under EPL
Copyright 2011 Hugo Duncan.