[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/dash f96196a 289/426: Merge pull request #75 from Fuco1
From: |
Phillip Lord |
Subject: |
[elpa] externals/dash f96196a 289/426: Merge pull request #75 from Fuco1/prefix |
Date: |
Tue, 04 Aug 2015 19:38:21 +0000 |
branch: externals/dash
commit f96196a5c3dd13a9f5d95acdf8faa435e435f269
Merge: 4098ea0 b44140a
Author: Magnar Sveen <address@hidden>
Commit: Magnar Sveen <address@hidden>
Merge pull request #75 from Fuco1/prefix
Add -is-prefix/suffix/infix-p
---
README.md | 35 +++++++++++++++++++++++++++++++++++
dash.el | 30 ++++++++++++++++++++++++++++++
dev/examples.el | 21 ++++++++++++++++++++-
3 files changed, 85 insertions(+), 1 deletions(-)
diff --git a/README.md b/README.md
index f52d46d..546c867 100644
--- a/README.md
+++ b/README.md
@@ -80,6 +80,9 @@ Include this in your emacs settings to get syntax
highlighting:
* [-only-some?](#-only-some-pred-list) `(pred list)`
* [-contains?](#-contains-list-element) `(list element)`
* [-same-items?](#-same-items-list-list2) `(list list2)`
+* [-is-prefix-p](#-is-prefix-p-prefix-list) `(prefix list)`
+* [-is-suffix-p](#-is-suffix-p-suffix-list) `(suffix list)`
+* [-is-infix-p](#-is-infix-p-infix-list) `(infix list)`
### Partitioning
@@ -635,6 +638,38 @@ The order of the elements in the lists does not matter.
(-same-items? '(1 2 3) '(1 2 3 4)) ;; => nil
```
+#### -is-prefix-p `(prefix list)`
+
+Return non-nil if `prefix` is prefix of `list`.
+
+```cl
+(-is-prefix-p '(1 2 3) '(1 2 3 4 5)) ;; => t
+(-is-prefix-p '(1 2 3 4 5) '(1 2 3)) ;; => nil
+(-is-prefix-p '(1 3) '(1 2 3 4 5)) ;; => nil
+```
+
+#### -is-suffix-p `(suffix list)`
+
+Return non-nil if `suffix` is suffix of `list`.
+
+```cl
+(-is-suffix-p '(3 4 5) '(1 2 3 4 5)) ;; => t
+(-is-suffix-p '(1 2 3 4 5) '(3 4 5)) ;; => nil
+(-is-suffix-p '(3 5) '(1 2 3 4 5)) ;; => nil
+```
+
+#### -is-infix-p `(infix list)`
+
+Return non-nil if `infix` is infix of `list`.
+
+This operation runs in `o`(n^2) time
+
+```cl
+(-is-infix-p '(1 2 3) '(1 2 3 4 5)) ;; => t
+(-is-infix-p '(2 3 4) '(1 2 3 4 5)) ;; => t
+(-is-infix-p '(3 4 5) '(1 2 3 4 5)) ;; => t
+```
+
## Partitioning
diff --git a/dash.el b/dash.el
index 4d4ef4e..0022076 100644
--- a/dash.el
+++ b/dash.el
@@ -1016,6 +1016,30 @@ The order of the elements in the lists does not matter."
(defalias '-same-items-p '-same-items?)
+(defun -is-prefix-p (prefix list)
+ "Return non-nil if PREFIX is prefix of LIST."
+ (--each-while list (equal (car prefix) it)
+ (!cdr prefix))
+ (not prefix))
+
+(defun -is-suffix-p (suffix list)
+ "Return non-nil if SUFFIX is suffix of LIST."
+ (-is-prefix-p (nreverse suffix) (nreverse list)))
+
+(defun -is-infix-p (infix list)
+ "Return non-nil if INFIX is infix of LIST.
+
+This operation runs in O(n^2) time"
+ (let (done)
+ (while (and (not done) list)
+ (setq done (-is-prefix-p infix list))
+ (!cdr list))
+ done))
+
+(defalias '-is-prefix? '-is-prefix-p)
+(defalias '-is-suffix? '-is-suffix-p)
+(defalias '-is-infix? '-is-infix-p)
+
(defun -sort (comparator list)
"Sort LIST, stably, comparing elements using COMPARATOR.
Returns the sorted list. LIST is NOT modified by side effects.
@@ -1355,6 +1379,12 @@ structure such as plist or alist."
"-contains-p"
"-same-items?"
"-same-items-p"
+ "-is-prefix-p"
+ "-is-prefix?"
+ "-is-suffix-p"
+ "-is-suffix?"
+ "-is-infix-p"
+ "-is-infix?"
"-sort"
"--sort"
"-list"
diff --git a/dev/examples.el b/dev/examples.el
index c0ae5bf..4568f60 100644
--- a/dev/examples.el
+++ b/dev/examples.el
@@ -233,7 +233,26 @@
(-same-items? '(1 2 3) '(3 2 1)) => t
(-same-items? '(1 2 3) '(1 2 3 4)) => nil
(-same-items? '((a . 1) (b . 2)) '((a . 1) (b . 2))) => t
- (-same-items? '(1 2 3) '(2 3 1)) => t))
+ (-same-items? '(1 2 3) '(2 3 1)) => t)
+
+ (defexamples -is-prefix-p
+ (-is-prefix-p '(1 2 3) '(1 2 3 4 5)) => t
+ (-is-prefix-p '(1 2 3 4 5) '(1 2 3)) => nil
+ (-is-prefix-p '(1 3) '(1 2 3 4 5)) => nil
+ (-is-prefix-p '(1 2 3) '(1 2 4 5)) => nil)
+
+ (defexamples -is-suffix-p
+ (-is-suffix-p '(3 4 5) '(1 2 3 4 5)) => t
+ (-is-suffix-p '(1 2 3 4 5) '(3 4 5)) => nil
+ (-is-suffix-p '(3 5) '(1 2 3 4 5)) => nil
+ (-is-suffix-p '(3 4 5) '(1 2 3 5)) => nil)
+
+ (defexamples -is-infix-p
+ (-is-infix-p '(1 2 3) '(1 2 3 4 5)) => t
+ (-is-infix-p '(2 3 4) '(1 2 3 4 5)) => t
+ (-is-infix-p '(3 4 5) '(1 2 3 4 5)) => t
+ (-is-infix-p '(2 3 4) '(1 2 4 5)) => nil
+ (-is-infix-p '(2 4) '(1 2 3 4 5)) => nil))
(def-example-group "Partitioning" nil
(defexamples -split-at
- [elpa] externals/dash 8707aaf 367/426: Update docs, (continued)
- [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
- [elpa] externals/dash c08fcba 299/426: Fixed documentation of `-last-item'., Phillip Lord, 2015/08/04
- [elpa] externals/dash f96196a 289/426: Merge pull request #75 from Fuco1/prefix,
Phillip Lord <=
- [elpa] externals/dash afe2781 388/426: Merge pull request #109 from bbatsov/threading-indentation, Phillip Lord, 2015/08/04
- [elpa] externals/dash 6b64ea7 303/426: Add functions for flexibly zipping uneven lists, Phillip Lord, 2015/08/04
- [elpa] externals/dash cd137e0 310/426: `-slice` should not fill the returned list with nils if to > length, Phillip Lord, 2015/08/04
- [elpa] externals/dash 5219ac0 422/426: [-let] Eliminate useless re-binding of symbols when sources are immutable, Phillip Lord, 2015/08/04
- [elpa] externals/dash a06e66e 382/426: Add test for clean byte compilation, Phillip Lord, 2015/08/04
- [elpa] externals/dash 43dcd37 295/426: Only eval NUM in --dotimes once, Phillip Lord, 2015/08/04
- [elpa] externals/dash 4ecfea6 296/426: Merge pull request #79 from Fuco1/debug-forms, Phillip Lord, 2015/08/04
- [elpa] externals/dash 624c501 306/426: Add `-table` and `-table-flat`, Phillip Lord, 2015/08/04
- [elpa] externals/dash cf7ca23 415/426: [Fix #97] Add -remove-item, Phillip Lord, 2015/08/04
- [elpa] externals/dash 2eefbec 386/426: Don't use an inline comment on a line of its own, Phillip Lord, 2015/08/04