[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/dash dd30a1f 047/316: [Feature #196] Add -powerset and
From: |
ELPA Syncer |
Subject: |
[elpa] externals/dash dd30a1f 047/316: [Feature #196] Add -powerset and -permutations (#203) |
Date: |
Mon, 15 Feb 2021 15:57:22 -0500 (EST) |
branch: externals/dash
commit dd30a1fbbae0201cfd0b861e3150ba6ea5d500fd
Author: holomorph <mvoteiza@udel.edu>
Commit: Matus Goljer <dota.keys@gmail.com>
[Feature #196] Add -powerset and -permutations (#203)
---
dash.el | 16 ++++++++++++++++
dev/examples.el | 9 +++++++++
2 files changed, 25 insertions(+)
diff --git a/dash.el b/dash.el
index 27dd2c1..a094e41 100644
--- a/dash.el
+++ b/dash.el
@@ -1959,6 +1959,22 @@ The test for equality is done with `equal',
or with `-compare-fn' if that's non-nil."
(--filter (not (-contains? list2 it)) list))
+(defun -powerset (list)
+ "Return the power set of LIST."
+ (if (null list) '(())
+ (let ((last (-powerset (cdr list))))
+ (append (mapcar (lambda (x) (cons (car list) x)) last)
+ last))))
+
+(defun -permutations (list)
+ "Return the permutations of LIST."
+ (if (null list) '(())
+ (apply #'append
+ (mapcar (lambda (x)
+ (mapcar (lambda (perm) (cons x perm))
+ (-permutations (remove x list))))
+ list))))
+
(defun -contains? (list element)
"Return non-nil if LIST contains ELEMENT.
diff --git a/dev/examples.el b/dev/examples.el
index a35ae33..092e57e 100644
--- a/dev/examples.el
+++ b/dev/examples.el
@@ -565,6 +565,15 @@ new list."
(-intersection '(1 2 3) '(4 5 6)) => '()
(-intersection '(1 2 3 4) '(3 4 5 6)) => '(3 4))
+ (defexamples -powerset
+ (-powerset '()) => '(nil)
+ (-powerset '(x y z)) => '((x y z) (x y) (x z) (x) (y z) (y) (z) nil))
+
+ (defexamples -permutations
+ (-permutations '()) => '(nil)
+ (-permutations '(1 2)) => '((1 2) (2 1))
+ (-permutations '(a b c)) => '((a b c) (a c b) (b a c) (b c a) (c a b) (c b
a)))
+
(defexamples -distinct
(-distinct '()) => '()
(-distinct '(1 2 2 4)) => '(1 2 4)))
- [elpa] externals/dash 070b569 156/316: Add missing indent declaration for ‘-some->’ and siblings, (continued)
- [elpa] externals/dash 070b569 156/316: Add missing indent declaration for ‘-some->’ and siblings, ELPA Syncer, 2021/02/15
- [elpa] externals/dash 800c25d 166/316: feat(docs): simplify (function x) to #'x, ELPA Syncer, 2021/02/15
- [elpa] externals/dash 53323ec 169/316: Fix typo and its copies, ELPA Syncer, 2021/02/15
- [elpa] externals/dash fe9bbc2 170/316: Merge pull request #334 from tarsiiformes/typo, ELPA Syncer, 2021/02/15
- [elpa] externals/dash e4e5269 180/316: Finish last change to package keywords, ELPA Syncer, 2021/02/15
- [elpa] externals/dash b329938 182/316: Update CI configuration, ELPA Syncer, 2021/02/15
- [elpa] externals/dash 7629dae 183/316: Add dir-locals-file with useful settings, ELPA Syncer, 2021/02/15
- [elpa] externals/dash 84721fc 206/316: Optimize -repeat a bit, ELPA Syncer, 2021/02/15
- [elpa] externals/dash d983d4f 217/316: Fix -doto, ELPA Syncer, 2021/02/15
- [elpa] externals/dash 66e3e94 079/316: Define -second-item through to -fifth-item, ELPA Syncer, 2021/02/15
- [elpa] externals/dash dd30a1f 047/316: [Feature #196] Add -powerset and -permutations (#203),
ELPA Syncer <=
- [elpa] externals/dash 5f7f2d6 056/316: Add example for an iota error condition, ELPA Syncer, 2021/02/15
- [elpa] externals/dash 524e6fe 057/316: Fix -map-last docs (#220), ELPA Syncer, 2021/02/15
- [elpa] externals/dash a3b40f8 058/316: Make --> bind IT for use anywhere in FORMS, and add -as->., ELPA Syncer, 2021/02/15
- [elpa] externals/dash 13f9ece 060/316: add tests for nesting anaphoric macros., ELPA Syncer, 2021/02/15
- [elpa] externals/dash d7b769b 065/316: Use standard Emacs quoting for bound symbols, ELPA Syncer, 2021/02/15
- [elpa] externals/dash b4faa93 066/316: Merge pull request #224 from Wilfred/when-let-docstring, ELPA Syncer, 2021/02/15
- [elpa] externals/dash 0df0ff1 067/316: Merge pull request #222 from zck/partition-before-after, ELPA Syncer, 2021/02/15
- [elpa] externals/dash dcb0ec1 069/316: Merge pull request #232 from Wilfred/improve_docs_wording, ELPA Syncer, 2021/02/15
- [elpa] externals/dash c026c46 073/316: Merge pull request #240 from basil-conto/239, ELPA Syncer, 2021/02/15
- [elpa] externals/dash bdcaf68 074/316: Merge pull request #236 from Wilfred/robust-docs-generation, ELPA Syncer, 2021/02/15