Re: [ANN] packthread 0.1.10

2018-04-04 Thread Matching Socks
Those are also good occasions for the standard-library *as->*

user> (-> 4
  (as-> x (let [n 2]
(+ x n))) 
  inc)
7

-- 
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.


Re: [ANN] packthread 0.1.10

2018-04-03 Thread Alan Thompson
If you are interested in alternatives to `clojure.core/->`, you may be
interested in the `it->` macro from the Tupelo library
.  Here is a
summary:

=

Usage examples for tupelo.core/it→
Name:
"it-thread" (literate threading macro)

Homepage: https://github.com/cloojure/tupelo
Lein
coords: [tupelo "0.9.75"]

Usage: clojure

  (it-> ...)

Why?

Because every time you’ve wanted to:

(ns xyz
  (:use tupelo.core))
(it-> 3
  (let [x 9]
(- x it))
  (inc it)
  (- it 6));=> 1

(it-> 42
  (if true
(inc it)
:blah)) ;=> 43
(it-> 42
  (if false
(inc it)
:blah)) ;=> :blah
; works same for `if-not`, `when`, `when-not`, etc.

(it-> 42
  (case 1
1 (inc it)
2 (dec it))) ;=> 43

(it-> 42
  (case 2
1 (inc it)
2 (dec it))) ;=> 41

(it-> 42
  (cond
(= 1 2)
(inc it))) ;=> 42

(it-> 42
  (cond
(= 1 1)
(dec it))) ;=> 41

(it-> 42
  (let [x 1]
(+ it x))) ;=> 43

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.

(ti-> 42
  (try
(inc it)
(catch Exception e
  (dec it))) ;=> 43

(it-> 42
  (try
(+ it :foo)
(catch Exception e
  (dec it ;=> 41

(it-> 42
  (try
(inc it)
(finally
  (+ 10 it ;=> 53
; with anonymous functions
(it-> 7
  ((fn [x y] (* x y)) it 3))  ;=> 21
(it-> 42
  #(-> % inc inc)) ;=> 44



On Tue, Apr 3, 2018 at 8:40 AM, Jason Felice 
wrote:

> This release handles `if-some` and `when-some` and supports ClojureScript.
>
> packthread
>
> https://github.com/maitria/packthread
>
> "Heavy" threading macros.
> Why?
>
> Because every time you've wanted to:
>
> (-> 42
>   (let [x 79]
> (+ x))
>   inc)
>
> but clojure wouldn't let you.
> +>
>
> Threads value through forms in much the same way as ->, except for
> special handling of the following forms:
>
> if,
> if-not, if-let, if-some, when, when-let, when-not, when-some
>
> 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-let, when-not, and when-some forms, the value is threaded
> through every form in the body, not just the last.
> 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
>
> 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
>
> do
>
> The current expr is threaded through the body forms of the do.
> 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
>
> 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
>
> in
>
> Threads inner expressions through a lens
> 
>  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 "pu