[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/dash 8f90dd7 121/316: Handle empty list in -reductions[
From: |
ELPA Syncer |
Subject: |
[elpa] externals/dash 8f90dd7 121/316: Handle empty list in -reductions[-r] |
Date: |
Mon, 15 Feb 2021 15:57:40 -0500 (EST) |
branch: externals/dash
commit 8f90dd7e33ba140ec5ad005c0ad58befface73dd
Author: Basil L. Contovounesios <contovob@tcd.ie>
Commit: Basil L. Contovounesios <contovob@tcd.ie>
Handle empty list in -reductions[-r]
---
dash.el | 8 ++++++--
dev/examples.el | 24 ++++++++++++++++--------
2 files changed, 22 insertions(+), 10 deletions(-)
diff --git a/dash.el b/dash.el
index e0437b8..fd0cb03 100644
--- a/dash.el
+++ b/dash.el
@@ -289,7 +289,7 @@ See also: `-reductions', `-reductions-r', `-reduce-r'"
See `-reduce' for explanation of the arguments.
See also: `-reductions-from', `-reductions-r', `-reduce-r'"
- (-reductions-from fn (car list) (cdr list)))
+ (and list (-reductions-from fn (car list) (cdr list))))
(defun -reductions-r-from (fn init list)
"Return a list of the intermediate values of the reduction.
@@ -305,7 +305,11 @@ See also: `-reductions-r', `-reductions', `-reduce'"
See `-reduce-r' for explanation of the arguments.
See also: `-reductions-r-from', `-reductions', `-reduce'"
- (-reductions-r-from fn (-last-item list) (-butlast list)))
+ (when list
+ (let ((rev (reverse list)))
+ (--reduce-from (cons (funcall fn it (car acc)) acc)
+ (list (car rev))
+ (cdr rev)))))
(defmacro --filter (form list)
"Anaphoric form of `-filter'.
diff --git a/dev/examples.el b/dev/examples.el
index 7ae2d1f..fff94d3 100644
--- a/dev/examples.el
+++ b/dev/examples.el
@@ -340,24 +340,32 @@ new list."
(--reduce-r (format "%s-%s" it acc) '()) => "nil-nil")
(defexamples -reductions-from
- (-reductions-from (lambda (a i) (format "(%s FN %s)" a i)) "INIT" '(1 2 3
4)) => '("INIT" "(INIT FN 1)" "((INIT FN 1) FN 2)" "(((INIT FN 1) FN 2) FN 3)"
"((((INIT FN 1) FN 2) FN 3) FN 4)")
+ (-reductions-from (lambda (a i) (format "(%s FN %d)" a i)) "INIT" '(1 2 3
4)) => '("INIT" "(INIT FN 1)" "((INIT FN 1) FN 2)" "(((INIT FN 1) FN 2) FN 3)"
"((((INIT FN 1) FN 2) FN 3) FN 4)")
(-reductions-from 'max 0 '(2 1 4 3)) => '(0 2 2 4 4)
- (-reductions-from '* 1 '(1 2 3 4)) => '(1 1 2 6 24))
+ (-reductions-from '* 1 '(1 2 3 4)) => '(1 1 2 6 24)
+ (-reductions-from '- 10 '(1)) => '(10 9)
+ (-reductions-from '- 10 ()) => '(10))
(defexamples -reductions-r-from
- (-reductions-r-from (lambda (i a) (format "(%s FN %s)" i a)) "INIT" '(1 2
3 4)) => '("(1 FN (2 FN (3 FN (4 FN INIT))))" "(2 FN (3 FN (4 FN INIT)))" "(3
FN (4 FN INIT))" "(4 FN INIT)" "INIT")
+ (-reductions-r-from (lambda (i a) (format "(%d FN %s)" i a)) "INIT" '(1 2
3 4)) => '("(1 FN (2 FN (3 FN (4 FN INIT))))" "(2 FN (3 FN (4 FN INIT)))" "(3
FN (4 FN INIT))" "(4 FN INIT)" "INIT")
(-reductions-r-from 'max 0 '(2 1 4 3)) => '(4 4 4 3 0)
- (-reductions-r-from '* 1 '(1 2 3 4)) => '(24 24 12 4 1))
+ (-reductions-r-from '* 1 '(1 2 3 4)) => '(24 24 12 4 1)
+ (-reductions-r-from '- 10 '(1)) => '(-9 10)
+ (-reductions-r-from '- 10 ()) => '(10))
(defexamples -reductions
- (-reductions (lambda (a i) (format "(%s FN %s)" a i)) '(1 2 3 4)) => '(1
"(1 FN 2)" "((1 FN 2) FN 3)" "(((1 FN 2) FN 3) FN 4)")
+ (-reductions (lambda (a i) (format "(%s FN %d)" a i)) '(1 2 3 4)) => '(1
"(1 FN 2)" "((1 FN 2) FN 3)" "(((1 FN 2) FN 3) FN 4)")
(-reductions '+ '(1 2 3 4)) => '(1 3 6 10)
- (-reductions '* '(1 2 3 4)) => '(1 2 6 24))
+ (-reductions '* '(1 2 3 4)) => '(1 2 6 24)
+ (-reductions '- '(1)) => '(1)
+ (-reductions '- ()) => ())
(defexamples -reductions-r
- (-reductions-r (lambda (i a) (format "(%s FN %s)" i a)) '(1 2 3 4)) =>
'("(1 FN (2 FN (3 FN 4)))" "(2 FN (3 FN 4))" "(3 FN 4)" 4)
+ (-reductions-r (lambda (i a) (format "(%d FN %s)" i a)) '(1 2 3 4)) =>
'("(1 FN (2 FN (3 FN 4)))" "(2 FN (3 FN 4))" "(3 FN 4)" 4)
(-reductions-r '+ '(1 2 3 4)) => '(10 9 7 4)
- (-reductions-r '* '(1 2 3 4)) => '(24 24 12 4))
+ (-reductions-r '* '(1 2 3 4)) => '(24 24 12 4)
+ (-reductions-r '- '(1)) => '(1)
+ (-reductions-r '- ()) => ())
(defexamples -count
(-count 'even? '(1 2 3 4 5)) => 2
- [elpa] externals/dash c1991d4 099/316: Merge pull request #262 from basil-conto/blc/common-prefix, (continued)
- [elpa] externals/dash c1991d4 099/316: Merge pull request #262 from basil-conto/blc/common-prefix, ELPA Syncer, 2021/02/15
- [elpa] externals/dash 48a5015 101/316: Merge pull request #265 from Wilfred/missing-keywords, ELPA Syncer, 2021/02/15
- [elpa] externals/dash beea1a3 098/316: Simplify --common-prefix implementation, ELPA Syncer, 2021/02/15
- [elpa] externals/dash 87d5fea 103/316: Merge pull request #266 from phillord/feature/travis-update, ELPA Syncer, 2021/02/15
- [elpa] externals/dash a74f4cf 105/316: Bump version in package declaration, ELPA Syncer, 2021/02/15
- [elpa] externals/dash 8c4e27f 108/316: Implement -setq, ELPA Syncer, 2021/02/15
- [elpa] externals/dash 578428a 117/316: Add some implementation commentary to '-each-r'., ELPA Syncer, 2021/02/15
- [elpa] externals/dash 3b08355 113/316: Use version from dash.el file when generating readme., ELPA Syncer, 2021/02/15
- [elpa] externals/dash a87df31 111/316: Merge pull request #269 from magnars/feature/smart-kv-destructuring, ELPA Syncer, 2021/02/15
- [elpa] externals/dash 406f6f3 112/316: Fix whitespace, ELPA Syncer, 2021/02/15
- [elpa] externals/dash 8f90dd7 121/316: Handle empty list in -reductions[-r],
ELPA Syncer <=
- [elpa] externals/dash 453c775 115/316: Fix -setq docstring fn reference, ELPA Syncer, 2021/02/15
- [elpa] externals/dash 85e8f62 119/316: Merge pull request #274 from magnars/doublep-each-r, ELPA Syncer, 2021/02/15
- [elpa] externals/dash 1e22ef6 125/316: Merge pull request #263 from basil-conto/blc/common-suffix, ELPA Syncer, 2021/02/15
- [elpa] externals/dash 78fee36 190/316: * .dir-locals.el (sh-mode): Enforce indentation., ELPA Syncer, 2021/02/15
- [elpa] externals/dash 1d897cc 199/316: Simplify examples-to-docs a bit, ELPA Syncer, 2021/02/15
- [elpa] externals/dash 3d38fa2 213/316: Use actual dash-functional.el version in manual, ELPA Syncer, 2021/02/15
- [elpa] externals/dash 92393c7 220/316: Clean up core definitions, ELPA Syncer, 2021/02/15
- [elpa] externals/dash 3034638 232/316: Tidy up -grade-up and -grade-down a bit, ELPA Syncer, 2021/02/15
- [elpa] externals/dash 9256290 241/316: * dash.el (-->): Indent with 1 distinguished arg., ELPA Syncer, 2021/02/15
- [elpa] externals/dash 7a9c937 250/316: Translate non-printable chars in docs, ELPA Syncer, 2021/02/15