From 6370487b72c9f03baeca91d41f3f7f308381bf30 Mon Sep 17 00:00:00 2001 From: Alois Date: Wed, 13 May 2015 11:00:57 +0200 Subject: Update clojure.html.markdown --- clojure.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'clojure.html.markdown') diff --git a/clojure.html.markdown b/clojure.html.markdown index 7917ab08..a125d18f 100644 --- a/clojure.html.markdown +++ b/clojure.html.markdown @@ -22,7 +22,7 @@ and often automatically. ; Clojure is written in "forms", which are just ; lists of things inside parentheses, separated by whitespace. ; -; The clojure reader assumes that the first thing is a +; The clojure reader assumes that the first thing is a ; function or macro to call, and the rest are arguments. ; The first call in a file should be ns, to set the namespace -- cgit v1.2.3 From aea4d998b446185ab66a0800e470bc36c132362a Mon Sep 17 00:00:00 2001 From: Adam Bard Date: Sun, 18 Oct 2015 00:31:19 +0800 Subject: Copy arrow docs from french. --- clojure.html.markdown | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'clojure.html.markdown') diff --git a/clojure.html.markdown b/clojure.html.markdown index a125d18f..58e835c9 100644 --- a/clojure.html.markdown +++ b/clojure.html.markdown @@ -264,6 +264,31 @@ keymap ; => {:a 1, :b 2, :c 3} (print "Saying hello to " name) (str "Hello " name)) ; => "Hello Urkel" (prints "Saying hello to Urkel") + +; Use the threading macros (-> and ->>) to express transformations of +; data more clearly. + +; The "Thread-first" macro (->) inserts into each form the result of +; the previous, as the first argument (second item) +(-> + {:a 1 :b 2} + (assoc :c 3) ;=> (assoc {:a 1 :b 2} :c 3) + (dissoc :b)) ;=> (dissoc (assoc {:a 1 :b 2} :c 3) :b) + +; This expression could be written as: +; (dissoc (assoc {:a 1 :b 2} :c 3) :b) +; and evaluates to {:a 1 :c 3} + +; The double arrow does the same thing, but inserts the result of +; each line at the *end* of the form. This is useful for collection +; operations in particular: +(->> + (range 10) + (map inc) ;=> (map inc (range 10) + (filter odd?) ;=> (filter odd? (map inc (range 10)) + (into [])) ;=> (into [] (filter odd? (map inc (range 10))) + ; Result: [1 3 5 7 9] + ; Modules ;;;;;;;;;;;;;;; -- cgit v1.2.3 From b552fe30c2f3562cf670a9e7655ff834deb3b551 Mon Sep 17 00:00:00 2001 From: Rafik NACCACHE Date: Sun, 2 Oct 2016 12:55:49 +0100 Subject: Add as-> macro documentation (#2392) * Add as-> macro documentation * Add as-> in english clojure.html.markdown --- clojure.html.markdown | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'clojure.html.markdown') diff --git a/clojure.html.markdown b/clojure.html.markdown index 58e835c9..bf9258f7 100644 --- a/clojure.html.markdown +++ b/clojure.html.markdown @@ -289,6 +289,19 @@ keymap ; => {:a 1, :b 2, :c 3} (into [])) ;=> (into [] (filter odd? (map inc (range 10))) ; Result: [1 3 5 7 9] +; When you are in a situation where you want more freedom as where to +; put the result of previous data transformations in an +; expression, you can use the as-> macro. With it, you can assign a +; specific name to transformations' output ans use it as a +; placeholder in your chained expressions: + +(as-> [1 2 3] input + (map inc input);=> You can use last transform's output at the last position + (nth input 4) ;=> and at the second position, in the same expression + (conj [4 5 6] input [8 9 10])) ;=> or in the middle ! + + + ; Modules ;;;;;;;;;;;;;;; -- cgit v1.2.3 From c7f2b23f2fe033ad004c4c6913ba9c37335bd6af Mon Sep 17 00:00:00 2001 From: "Soumya D. Sanyal" Date: Sun, 23 Oct 2016 08:19:13 -0400 Subject: typo fix in clojure.html.markdown nth input expression from 4 to 2 resolves: IndexOutOfBoundsException clojure.lang.RT.nthFrom (RT.java:885) (#2493) --- clojure.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'clojure.html.markdown') diff --git a/clojure.html.markdown b/clojure.html.markdown index bf9258f7..bfe8d79e 100644 --- a/clojure.html.markdown +++ b/clojure.html.markdown @@ -297,7 +297,7 @@ keymap ; => {:a 1, :b 2, :c 3} (as-> [1 2 3] input (map inc input);=> You can use last transform's output at the last position - (nth input 4) ;=> and at the second position, in the same expression + (nth input 2) ;=> and at the second position, in the same expression (conj [4 5 6] input [8 9 10])) ;=> or in the middle ! -- cgit v1.2.3 From b890a98a49c9bed1c304d11e58331eb76bcb2c04 Mon Sep 17 00:00:00 2001 From: Evan Hahn Date: Sat, 29 Apr 2017 01:11:05 -0700 Subject: [clojure/en] Fix typo: "ans" should be "and" (#2717) --- clojure.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'clojure.html.markdown') diff --git a/clojure.html.markdown b/clojure.html.markdown index bfe8d79e..7830f228 100644 --- a/clojure.html.markdown +++ b/clojure.html.markdown @@ -292,7 +292,7 @@ keymap ; => {:a 1, :b 2, :c 3} ; When you are in a situation where you want more freedom as where to ; put the result of previous data transformations in an ; expression, you can use the as-> macro. With it, you can assign a -; specific name to transformations' output ans use it as a +; specific name to transformations' output and use it as a ; placeholder in your chained expressions: (as-> [1 2 3] input -- cgit v1.2.3