From 9424dd8cd23d8f7ed27f48c0785bde46c48d6451 Mon Sep 17 00:00:00 2001 From: zardoz03 Date: Tue, 5 Dec 2023 09:41:54 +0000 Subject: [PATCH 1/3] Add: ->>as-> for use with ->>. --- dash.el | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/dash.el b/dash.el index d9007175..b7ca75f7 100644 --- a/dash.el +++ b/dash.el @@ -2127,6 +2127,19 @@ VARIABLE to the result of the first form, and so forth." ,variable ,@(cdr forms))))) +(defmacro ->>as-> (variable &rest forms) + "Ending with VALUE, thread VARIABLE through all the other FORMS. +Variant of `-as->' but intended for use with `->>'. + +\(fn VARIABLE FORMS ... VALUE)" + (if (null forms) + (error "No Value nor Forms given!") + (let ((val (car (last forms))) + (args (-butlast forms))) + (if (null args) + `,val + `(-as-> ,val ,variable ,@args))))) + (defmacro -some-> (x &optional form &rest more) "When expr is non-nil, thread it through the first form (via `->'), and when that result is non-nil, through the next form, etc." From 54612330a57424ec388ed316226c687c45f5afc6 Mon Sep 17 00:00:00 2001 From: zardoz03 Date: Tue, 5 Dec 2023 09:51:51 +0000 Subject: [PATCH 2/3] test: ->>as-> --- dev/examples.el | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/dev/examples.el b/dev/examples.el index 527e0f35..e0785cab 100644 --- a/dev/examples.el +++ b/dev/examples.el @@ -2064,6 +2064,14 @@ or readability." (-as-> "def" string (concat "abc" string "ghi") upcase) => "ABCDEFGHI" (-as-> "def" string (concat "abc" string "ghi") (upcase string)) => "ABCDEFGHI") + (defexamples ->>as-> + (->>as-> i 1) => 1 + (->>as-> i (+ i 1) 1) => 2 + (->> 1 (->>as-> i (+ i 1))) => 2 + (->> "def" (->>as-> string (concat "abc" string "ghi"))) => "abcdefghi" + (->> "def" (->>as-> string (concat "abc" string "ghi")) upcase) => "ABCDEFGHI" + (->> "def" (->>as-> string (concat "abc" string "ghi") (upcase string))) => "ABCDEFGHI") + (defexamples -some-> (-some-> '(2 3 5)) => '(2 3 5) (-some-> 5 square) => 25 From daa8d55bb0dfb207cae7d5c718ade68d31cbcb36 Mon Sep 17 00:00:00 2001 From: zardoz03 Date: Tue, 5 Dec 2023 10:07:40 +0000 Subject: [PATCH 3/3] README: add ->>as-> to readme --- README.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/README.md b/README.md index 09c76bdb..3bd19015 100644 --- a/README.md +++ b/README.md @@ -319,6 +319,7 @@ or readability. * [`->>`](#--x-optional-form-rest-more) `(x &optional form &rest more)` * [`-->`](#---x-rest-forms) `(x &rest forms)` * [`-as->`](#-as--value-variable-rest-forms) `(value variable &rest forms)` +* [`->>as->`](#->>as->variable-rest-forms-value) `(value forms ... value)` * [`-some->`](#-some--x-optional-form-rest-more) `(x &optional form &rest more)` * [`-some->>`](#-some--x-optional-form-rest-more) `(x &optional form &rest more)` * [`-some-->`](#-some---expr-rest-forms) `(expr &rest forms)` @@ -2528,6 +2529,17 @@ In the first form, bind `variable` to `value`. In the second form, bind (-as-> 3 my-var) ;; => 3 ``` +#### ->>as-> (variable forms ... value) +Ending with VALUE, thread VARIABLE through all the other FORMS. +Variant of `-as->` but intended for use with `->>`. + +```el +(->>as-> i (+ i 1) 1) ;; => 2 +;; ^ unintuitive on its own. +(->> 1 (->>as-> i (+ i 1))) ;; => 2 +(->> "def" (->>as-> string (concat "abc" string "ghi"))) ;; => "abcdefghi" +``` + #### -some-> `(x &optional form &rest more)` When expr is non-`nil`, thread it through the first form (via [`->`](#--x-optional-form-rest-more)),