Changes: * Allow fn+>'s first arg to be destructuring. packthread
"Smarter" threading macros. <https://github.com/maitria/packthread#why>Why? Because every time you've wanted to: (-> 42 (let [x 79] (+ x) inc) but clojure wouldn't let you. <https://github.com/maitria/packthread#>+> Threads value through forms in much the same way as ->, except for special handling of the following forms: <https://github.com/maitria/packthread#if-if-not-if-let-when-when-not-when-let>if, if-not, if-let, when, when-not, when-let: The value is threaded through the *then* and *else* clauses independently, leaving the test conditions alone. If an else clause is missing, it is will be supplied as though the value had been threaded through identity. For example, (+> 42 (if true inc)) ;=> 43 (+> 42 (if false inc)) ;=> 42 In when, when-not, and when-let forms, the value is threaded through every form in the body, not just the last. <https://github.com/maitria/packthread#case>case The values being compared are left untouched and the value is threaded through the expr clause of each condition. For example, (+> 42 (case 1 1 inc 2 dec)) ;=> 43 (+> 42 (case 2 1 inc 2 dec)) ;=> 41 <https://github.com/maitria/packthread#cond>cond The test clauses are left untouched and the value is threaded through the expr clauses of each condition. If there's no:else condition, +> pretends it was (identity). For example, (+> 42 (cond (= 1 2) inc)) ;=> 42 (+> 42 (cond (= 1 1) dec)) ;=> 41 <https://github.com/maitria/packthread#do>do The current expr is threaded through the body forms of the do. <https://github.com/maitria/packthread#let>let The current expression is threaded through the body of the let form, with the bindings in place. For example: (+> 42 (let [x 1] (+ x))) ;=> 43 <https://github.com/maitria/packthread#try>try The current expression is threaded through the body of the try form. The *same* value is threaded through each catchclause and any finally clause. (+> 42 (try inc (catch Exception e dec)) ;=> 43 (+> 42 (try (+ :foo) (catch Exception e dec))) ;=> 41 (+> 42 (try inc (finally dec))) ;=> 42 <https://github.com/maitria/packthread#in>in Threads inner expressions through a lens <http://repository.upenn.edu/cgi/viewcontent.cgi?article=1044&context=cis_reports> of value. lens is a function with two arities - 1 and 2. The 1-arity body is the "get" function, while the 2-arity body is the "putback" function. "get" lifts the value into the new context, while "putback" translates the value back to the original context. For example, (+> 42 (in (fn ([v] (/ v 2)) ([v u] (* u 2))) inc)) ;=> 85/2 This can be thought of as 'lifting' the body expressions into the 'world where things are half as large'. As a special case, if lens is a keyword, in assumes that value is a map and that sub-key are threaded through the inner expressions. For example, (+> {:hello 42} (in :hello (+ 5))) ;=> {:hello 47} This macro can only be used inside +> or +>>. <https://github.com/maitria/packthread#-1>+>> Threads expressions like ->>, except with the handling of the special forms above. <https://github.com/maitria/packthread#fn>fn+> Like fn, except threads the function's first argument through the body using +> . The parameter vector can be omitted, in which case the resulting function takes one parameter. ((fn+> [x y] (+ x)) 7 3) ;=> 14 ((fn+> inc inc) 42) ;=> 44 <https://github.com/maitria/packthread#installing>Installing Leiningen <http://github.com/technomancy/leiningen/> dependency information: [com.maitria/packthread "0.1.7"] <https://github.com/maitria/packthread#usage>Usage (require '[packthread.core :refer :all]) (+> 42 (if true inc)) ;=> 43 See core_test.clj <https://github.com/maitria/packthread/blob/master/test/packthread/core_test.clj> for examples of usage. <https://github.com/maitria/packthread#license>License Copyright 2014 Maitria You have permission to use this in any way you like (modify it, sell it, republish it), provided you agree to all the following conditions: - you don't mislead anyone about it - you don't interfere with our ability to use it - you release us from any claims of liability if it causes problems for you -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.