[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/dash 13a4718 059/316: Add new partition-before, -after
From: |
ELPA Syncer |
Subject: |
[elpa] externals/dash 13a4718 059/316: Add new partition-before, -after methods. |
Date: |
Mon, 15 Feb 2021 15:57:25 -0500 (EST) |
branch: externals/dash
commit 13a4718b3d207976a21df08008e7b78000218385
Author: Zachary Kanfer <zkanfer@gmail.com>
Commit: Zachary Kanfer <zkanfer@gmail.com>
Add new partition-before, -after methods.
The new methods are -partition-before-pred, -partition-after-pred,
-partition-before-item, and -partition-after-item.
---
dash.el | 30 ++++++++++++++++++++++++++++++
dev/examples.el | 31 +++++++++++++++++++++++++++++++
2 files changed, 61 insertions(+)
diff --git a/dash.el b/dash.el
index 10b1f05..2e34cbe 100644
--- a/dash.el
+++ b/dash.el
@@ -1032,6 +1032,36 @@ returns the header value, but only after seeing at least
one
other value (the body)."
(--partition-by-header (funcall fn it) list))
+(defun -partition-after-pred (pred list)
+ "Partition directly after each time PRED is true on an element of LIST."
+ (when list
+ (let ((rest (-partition-after-pred pred
+ (cdr list))))
+ (if (funcall pred (car list))
+ ;;split after (car list)
+ (cons (list (car list))
+ rest)
+
+ ;;don't split after (car list)
+ (cons (cons (car list)
+ (car rest))
+ (cdr rest))))))
+
+(defun -partition-before-pred (pred list)
+ "Partition directly before each time PRED is true on an element of LIST."
+ (nreverse (-map #'reverse
+ (-partition-after-pred pred (reverse list)))))
+
+(defun -partition-after-item (item list)
+ "Partition directly after each time ITEM appears in LIST."
+ (-partition-after-pred (lambda (ele) (equal ele item))
+ list))
+
+(defun -partition-before-item (item list)
+ "Partition directly before each time ITEM appears in LIST."
+ (-partition-before-pred (lambda (ele) (equal ele item))
+ list))
+
(defmacro --group-by (form list)
"Anaphoric form of `-group-by'."
(declare (debug t))
diff --git a/dev/examples.el b/dev/examples.el
index 7487292..aaa0bed 100644
--- a/dev/examples.el
+++ b/dev/examples.el
@@ -506,6 +506,37 @@ new list."
(--partition-by-header (> it 0) '(1 2 0 1 0 1 2 3 0)) => '((1 2 0) (1 0)
(1 2 3 0))
(-partition-by-header 'even? '(2 1 1 1 4 1 3 5 6 6 1)) => '((2 1 1 1) (4 1
3 5) (6 6 1)))
+ (defexamples -partition-after-pred
+ (-partition-after-pred #'oddp '()) => '()
+ (-partition-after-pred #'oddp '(1)) => '((1))
+ (-partition-after-pred #'oddp '(0 1)) => '((0 1))
+ (-partition-after-pred #'oddp '(1 1)) => '((1) (1))
+ (-partition-after-pred #'oddp '(0 0 0 1 0 1 1 0 1)) => '((0 0 0 1) (0 1)
(1) (0 1)))
+
+ (defexamples -partition-before-pred
+ (-partition-before-pred #'oddp '()) => '()
+ (-partition-before-pred #'oddp '(1)) => '((1))
+ (-partition-before-pred #'oddp '(0 1)) => '((0) (1))
+ (-partition-before-pred #'oddp '(1 1)) => '((1) (1))
+ (-partition-before-pred #'oddp '(0 1 0)) => '((0) (1 0))
+ (-partition-before-pred #'oddp '(0 0 0 1 0 1 1 0 1)) => '((0 0 0) (1 0)
(1) (1 0) (1)))
+
+ (defexamples -partition-before-item
+ (-partition-before-item 3 '()) => '()
+ (-partition-before-item 3 '(1)) => '((1))
+ (-partition-before-item 3 '(3)) => '((3))
+ (-partition-before-item 3 '(1 3)) => '((1) (3))
+ (-partition-before-item 3 '(1 3 4)) => '((1) (3 4))
+ (-partition-before-item 3 '(1 2 3 2 3 3 4)) => '((1 2) (3 2) (3) (3 4)))
+
+ (defexamples -partition-after-item
+ (-partition-after-item 3 '()) => '()
+ (-partition-after-item 3 '(1)) => '((1))
+ (-partition-after-item 3 '(3)) => '((3))
+ (-partition-after-item 3 '(3 1)) => '((3) (1))
+ (-partition-after-item 3 '(3 1 3)) => '((3) (1 3))
+ (-partition-after-item 3 '(3 2 3 3 4 5 3 2)) => '((3) (2 3) (3) (4 5 3)
(2)))
+
(defexamples -group-by
(-group-by 'even? '()) => '()
(-group-by 'even? '(1 1 2 2 2 3 4 6 8)) => '((nil . (1 1 3)) (t . (2 2 2 4
6 8)))
- [elpa] externals/dash 98e819e 053/316: Merge pull request #210 from Wilfred/car_opcode_with_first_item, (continued)
- [elpa] externals/dash 98e819e 053/316: Merge pull request #210 from Wilfred/car_opcode_with_first_item, ELPA Syncer, 2021/02/15
- [elpa] externals/dash 6a57833 054/316: Add -iota (#207), ELPA Syncer, 2021/02/15
- [elpa] externals/dash 1e14307 061/316: Merge pull request #221 from zck/it-anywhere-in-->, ELPA Syncer, 2021/02/15
- [elpa] externals/dash 0468a31 063/316: Merge pull request #223 from phillord/feature/doc-copyright, ELPA Syncer, 2021/02/15
- [elpa] externals/dash f69a9df 071/316: Replace -first with -some in -any?, ELPA Syncer, 2021/02/15
- [elpa] externals/dash 1422b70 042/316: Update info, ELPA Syncer, 2021/02/15
- [elpa] externals/dash 73a28ae 043/316: Fix function application in documentation, ELPA Syncer, 2021/02/15
- [elpa] externals/dash 53e641c 044/316: [Fix #202] -table-flat works on input of dimension 1, ELPA Syncer, 2021/02/15
- [elpa] externals/dash f04df47 048/316: Fix the debug declaration for -->, ELPA Syncer, 2021/02/15
- [elpa] externals/dash 81ef1ef 055/316: Replace string-to-int with string-to-number (#216), ELPA Syncer, 2021/02/15
- [elpa] externals/dash 13a4718 059/316: Add new partition-before, -after methods.,
ELPA Syncer <=
- [elpa] externals/dash ca2f767 064/316: Show (VAR VAL) in the function signature, ELPA Syncer, 2021/02/15
- [elpa] externals/dash 0297166 068/316: Docs: Clarify that we don't modify the original list, ELPA Syncer, 2021/02/15
- [elpa] externals/dash a57c2c3 082/316: Merge pull request #245 from duianto/patch-1, ELPA Syncer, 2021/02/15
- [elpa] externals/dash 5b549bc 085/316: Add missing fontification keywords, ELPA Syncer, 2021/02/15
- [elpa] externals/dash 0574686 089/316: Make tails and inits return all prefixes including the empty one., ELPA Syncer, 2021/02/15
- [elpa] externals/dash eb1231e 087/316: Add -reductions[-r][-from], ELPA Syncer, 2021/02/15
- [elpa] externals/dash 4e90743 093/316: Ensure ' in docstring code snippets is not replaced, ELPA Syncer, 2021/02/15
- [elpa] externals/dash 138c22a 097/316: Merge pull request #261 from basil-conto/blc/common-prefix, ELPA Syncer, 2021/02/15
- [elpa] externals/dash 3789b15 102/316: Change Emacs tested and supported versions., ELPA Syncer, 2021/02/15
- [elpa] externals/dash e9919f6 104/316: Release 2.14.0, ELPA Syncer, 2021/02/15