[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/dash 03b98ca 364/426: Make -if-let and -when-let famili
From: |
Phillip Lord |
Subject: |
[elpa] externals/dash 03b98ca 364/426: Make -if-let and -when-let families destructure their arguments |
Date: |
Tue, 04 Aug 2015 19:38:55 +0000 |
branch: externals/dash
commit 03b98ca5a90ba405356fd9a0ae5999d9eede1fad
Author: Fredrik Bergroth <address@hidden>
Commit: Fredrik Bergroth <address@hidden>
Make -if-let and -when-let families destructure their arguments
---
dash.el | 55 ++++++++++++++++++++++++-------------------------------
1 files changed, 24 insertions(+), 31 deletions(-)
diff --git a/dash.el b/dash.el
index d398e8b..96c581b 100644
--- a/dash.el
+++ b/dash.el
@@ -1116,68 +1116,61 @@ sorts it in descending order."
(defmacro -when-let (var-val &rest body)
"If VAL evaluates to non-nil, bind it to VAR and execute body.
-VAR-VAL should be a (VAR VAL) pair."
+VAR-VAL should be a (VAR VAL) pair.
+
+Note: binding is done according to `-let'."
(declare (debug ((symbolp form) body))
(indent 1))
- (let ((var (car var-val))
- (val (cadr var-val)))
- `(let ((,var ,val))
- (when ,var
- ,@body))))
+ `(-if-let ,var-val (progn ,@body)))
(defmacro -when-let* (vars-vals &rest body)
"If all VALS evaluate to true, bind them to their corresponding
VARS and execute body. VARS-VALS should be a list of (VAR VAL)
-pairs (corresponding to bindings of `let*')."
+pairs.
+
+Note: binding is done according to `-let'."
(declare (debug ((&rest (symbolp form)) body))
(indent 1))
- (if (= (length vars-vals) 1)
- `(-when-let ,(car vars-vals)
- ,@body)
- `(-when-let ,(car vars-vals)
- (-when-let* ,(cdr vars-vals)
- ,@body))))
+ `(-if-let* ,vars-vals (progn ,@body)))
(defmacro --when-let (val &rest body)
"If VAL evaluates to non-nil, bind it to `it' and execute
body."
(declare (debug (form body))
(indent 1))
- `(let ((it ,val))
- (when it
- ,@body)))
+ `(--if-let ,val (progn ,@body)))
(defmacro -if-let (var-val then &rest else)
"If VAL evaluates to non-nil, bind it to VAR and do THEN,
-otherwise do ELSE. VAR-VAL should be a (VAR VAL) pair."
+otherwise do ELSE. VAR-VAL should be a (VAR VAL) pair.
+
+Note: binding is done according to `-let'."
(declare (debug ((symbolp form) form body))
(indent 2))
- (let ((var (car var-val))
- (val (cadr var-val)))
- `(let ((,var ,val))
- (if ,var ,then ,@else))))
+ `(-if-let* (,var-val) ,then ,@else))
(defmacro -if-let* (vars-vals then &rest else)
"If all VALS evaluate to true, bind them to their corresponding
VARS and do THEN, otherwise do ELSE. VARS-VALS should be a list
-of (VAR VAL) pairs (corresponding to the bindings of `let*')."
+of (VAR VAL) pairs.
+
+Note: binding is done according to `-let'."
(declare (debug ((&rest (symbolp form)) form body))
(indent 2))
- (let ((first-pair (car vars-vals))
- (rest (cdr vars-vals)))
- (if (= (length vars-vals) 1)
- `(-if-let ,first-pair ,then ,@else)
- `(-if-let ,first-pair
- (-if-let* ,rest ,then ,@else)
- ,@else))))
+ (->> vars-vals
+ (-mapcat (-lambda ((pat src)) (dash--match pat src)))
+ (-reduce-r-from
+ (-lambda ((var val) memo)
+ `(let ((,var ,val))
+ (if ,var ,memo ,@else)))
+ then)))
(defmacro --if-let (val then &rest else)
"If VAL evaluates to non-nil, bind it to `it' and do THEN,
otherwise do ELSE."
(declare (debug (form form body))
(indent 2))
- `(let ((it ,val))
- (if it ,then ,@else)))
+ `(-if-let (it ,val) ,then ,@else))
(defun dash--match-ignore-place-p (symbol)
"Return non-nil if SYMBOL is a symbol and starts with _."
- [elpa] externals/dash f7664c6 352/426: [-let] Add &keys support for cons matcher, (continued)
- [elpa] externals/dash f7664c6 352/426: [-let] Add &keys support for cons matcher, Phillip Lord, 2015/08/04
- [elpa] externals/dash 4b63be1 362/426: Declare --mapcat macro before using it. #102, Phillip Lord, 2015/08/04
- [elpa] externals/dash 0310e0e 359/426: Update docs, Phillip Lord, 2015/08/04
- [elpa] externals/dash 0fc5d73 351/426: [-let] Make the cons matcher temp-bind as late as possible, Phillip Lord, 2015/08/04
- [elpa] externals/dash 75d29a2 363/426: Declare --iterate macro before using it. #102, Phillip Lord, 2015/08/04
- [elpa] externals/dash 3bdf60b 365/426: Add some examples, Phillip Lord, 2015/08/04
- [elpa] externals/dash 65a3736 349/426: [-let] Fix improper list non-symbol last argument handler, Phillip Lord, 2015/08/04
- [elpa] externals/dash 549bfd3 366/426: Reorder macros to make sure they are declared before being used, Phillip Lord, 2015/08/04
- [elpa] externals/dash db7f651 353/426: [-let] Simplify the conditions in dash--match-cons-1, Phillip Lord, 2015/08/04
- [elpa] externals/dash c6b92ae 324/426: Reorder the examples into more meaningful blocks, Phillip Lord, 2015/08/04
- [elpa] externals/dash 03b98ca 364/426: Make -if-let and -when-let families destructure their arguments,
Phillip Lord <=
- [elpa] externals/dash 5e9c1a9 373/426: Add Fredrik Bergroth to the list of contributors, Phillip Lord, 2015/08/04
- [elpa] externals/dash 8707aaf 367/426: Update docs, Phillip Lord, 2015/08/04
- [elpa] externals/dash 63fa64f 368/426: Add links to references in readme, Phillip Lord, 2015/08/04
- [elpa] externals/dash d459b49 374/426: Fix typo, Phillip Lord, 2015/08/04
- [elpa] externals/dash 9e1a667 360/426: Do not map nodes on conses (be consistent with tree map), Phillip Lord, 2015/08/04
- [elpa] externals/dash 7185db8 311/426: [Issue #83] Add `step` to `-slice`, Phillip Lord, 2015/08/04
- [elpa] externals/dash 2b69c14 411/426: Add dash.info and dash.texi to repo, Phillip Lord, 2015/08/04
- [elpa] externals/dash c61fc34 417/426: Add -remove-first/last, -map-first/last, -replace-first/last, Phillip Lord, 2015/08/04
- [elpa] externals/dash fb51f8f 304/426: Merge pull request #88 from steventlamb/topic/zip_cycle_pad, Phillip Lord, 2015/08/04
- [elpa] externals/dash d0c6fc0 371/426: Merge pull request #104 from fbergroth/linkify-docs, Phillip Lord, 2015/08/04