[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/dash f8c8dc0 084/316: Add -tails and -inits
From: |
ELPA Syncer |
Subject: |
[elpa] externals/dash f8c8dc0 084/316: Add -tails and -inits |
Date: |
Mon, 15 Feb 2021 15:57:31 -0500 (EST) |
branch: externals/dash
commit f8c8dc002c651597d9ac121abb4879a94a56868b
Author: Matus Goljer <matus.goljer@gmail.com>
Commit: Matus Goljer <matus.goljer@gmail.com>
Add -tails and -inits
---
README.md | 22 ++++++++++++++++++++++
dash.el | 11 +++++++++++
dash.texi | 40 ++++++++++++++++++++++++++++++++++++++++
dev/examples.el | 10 ++++++++++
4 files changed, 83 insertions(+)
diff --git a/README.md b/README.md
index 0f42e38..17b9b24 100644
--- a/README.md
+++ b/README.md
@@ -208,6 +208,8 @@ Operations pretending lists are sets.
* [-intersection](#-intersection-list-list2) `(list list2)`
* [-powerset](#-powerset-list) `(list)`
* [-permutations](#-permutations-list) `(list)`
+* [-inits](#-inits-list) `(list)`
+* [-tails](#-tails-list) `(list)`
* [-distinct](#-distinct-list) `(list)`
### Other list operations
@@ -1481,6 +1483,26 @@ Return the permutations of `list`.
(-permutations '(a b c)) ;; => '((a b c) (a c b) (b a c) (b c a) (c a b) (c b
a))
```
+#### -inits `(list)`
+
+Return all non-empty prefixes of `list`.
+
+```el
+(-inits '(1 2 3 4)) ;; => '((1) (1 2) (1 2 3) (1 2 3 4))
+(-inits nil) ;; => nil
+(-inits '(1)) ;; => '((1))
+```
+
+#### -tails `(list)`
+
+Return all non-empty suffixes of `list`
+
+```el
+(-tails '(1 2 3 4)) ;; => '((1 2 3 4) (2 3 4) (3 4) (4))
+(-tails nil) ;; => nil
+(-tails '(1)) ;; => '((1))
+```
+
#### -distinct `(list)`
Return a new list with all duplicates removed.
diff --git a/dash.el b/dash.el
index 773f79a..aee31af 100644
--- a/dash.el
+++ b/dash.el
@@ -2075,6 +2075,17 @@ or with `-compare-fn' if that's non-nil."
(-permutations (remove x list))))
list))))
+(defun -inits (list)
+ "Return all non-empty prefixes of LIST."
+ (nreverse (-map 'reverse (-tails (nreverse list)))))
+
+(defun -tails (list)
+ "Return all non-empty suffixes of LIST"
+ (-reduce-r-from
+ (lambda (it acc)
+ (cons (cons it (car acc)) acc))
+ nil list))
+
(defun -contains? (list element)
"Return non-nil if LIST contains ELEMENT.
diff --git a/dash.texi b/dash.texi
index 909fc7e..6a60f65 100644
--- a/dash.texi
+++ b/dash.texi
@@ -2209,6 +2209,46 @@ Return the permutations of @var{list}.
@end example
@end defun
+@anchor{-inits}
+@defun -inits (list)
+Return all non-empty prefixes of @var{list}.
+
+@example
+@group
+(-inits '(1 2 3 4))
+ @result{} '((1) (1 2) (1 2 3) (1 2 3 4))
+@end group
+@group
+(-inits nil)
+ @result{} nil
+@end group
+@group
+(-inits '(1))
+ @result{} '((1))
+@end group
+@end example
+@end defun
+
+@anchor{-tails}
+@defun -tails (list)
+Return all non-empty suffixes of @var{list}
+
+@example
+@group
+(-tails '(1 2 3 4))
+ @result{} '((1 2 3 4) (2 3 4) (3 4) (4))
+@end group
+@group
+(-tails nil)
+ @result{} nil
+@end group
+@group
+(-tails '(1))
+ @result{} '((1))
+@end group
+@end example
+@end defun
+
@anchor{-distinct}
@defun -distinct (list)
Return a new list with all duplicates removed.
diff --git a/dev/examples.el b/dev/examples.el
index 6216ee1..796d933 100644
--- a/dev/examples.el
+++ b/dev/examples.el
@@ -607,6 +607,16 @@ new list."
(-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 -inits
+ (-inits '(1 2 3 4)) => '((1) (1 2) (1 2 3) (1 2 3 4))
+ (-inits nil) => nil
+ (-inits '(1)) => '((1)))
+
+ (defexamples -tails
+ (-tails '(1 2 3 4)) => '((1 2 3 4) (2 3 4) (3 4) (4))
+ (-tails nil) => nil
+ (-tails '(1)) => '((1)))
+
(defexamples -distinct
(-distinct '()) => '()
(-distinct '(1 2 2 4)) => '(1 2 4)))
- [elpa] externals/dash d7b769b 065/316: Use standard Emacs quoting for bound symbols, (continued)
- [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
- [elpa] externals/dash 3493fc9 076/316: Merge pull request #242 from magnars/fix-infinite-loop-zip-interleave, ELPA Syncer, 2021/02/15
- [elpa] externals/dash 057e55c 081/316: Update examples.el, remove duplicate -third-item, ELPA Syncer, 2021/02/15
- [elpa] externals/dash 4b46527 080/316: Merge pull request #238 from Wilfred/more-item-accesses, ELPA Syncer, 2021/02/15
- [elpa] externals/dash e7764ea 083/316: Formatting, ELPA Syncer, 2021/02/15
- [elpa] externals/dash f8c8dc0 084/316: Add -tails and -inits,
ELPA Syncer <=
- [elpa] externals/dash d8bcf56 086/316: Add -running-sum and -running-product, ELPA Syncer, 2021/02/15
- [elpa] externals/dash 72b8d39 096/316: Add -common-prefix, ELPA Syncer, 2021/02/15
- [elpa] externals/dash 91d8cb0 091/316: Move inits and tails under reductions in the examples, ELPA Syncer, 2021/02/15
- [elpa] externals/dash e9c792f 094/316: Merge pull request #257 from Wilfred/update_docs, ELPA Syncer, 2021/02/15
- [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