[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/dash b44140a 288/426: Add -is-prefix/suffix/infix-p
From: |
Phillip Lord |
Subject: |
[elpa] externals/dash b44140a 288/426: Add -is-prefix/suffix/infix-p |
Date: |
Tue, 04 Aug 2015 19:38:20 +0000 |
branch: externals/dash
commit b44140accde3cd6815558288a351190ee7c5ba6f
Author: Matus Goljer <address@hidden>
Commit: Matus Goljer <address@hidden>
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 b201f0c 281/426: Add debug declarations and move indent declarations into `declare`, (continued)
- [elpa] externals/dash b201f0c 281/426: Add debug declarations and move indent declarations into `declare`, Phillip Lord, 2015/08/04
- [elpa] externals/dash 4e6a965 294/426: Still better debug declarations, Phillip Lord, 2015/08/04
- [elpa] externals/dash dab0d1c 384/426: Merge pull request #107 from fbergroth/workaround-byte-compiler, Phillip Lord, 2015/08/04
- [elpa] externals/dash 446c522 375/426: Release 2.10.0, Phillip Lord, 2015/08/04
- [elpa] externals/dash 2dfd748 298/426: Merge pull request #87 from steventlamb/topic/make_zip_n_ary, Phillip Lord, 2015/08/04
- [elpa] externals/dash a3021eb 313/426: Merge pull request #93 from lunaryorn/patch-1, Phillip Lord, 2015/08/04
- [elpa] externals/dash 8d2227d 380/426: Silence unused variable warning in -table, Phillip Lord, 2015/08/04
- [elpa] externals/dash f5264db 291/426: Merge pull request #77 from Fuco1/split-when, Phillip Lord, 2015/08/04
- [elpa] externals/dash c40fa44 383/426: Exclude byte compilation test on emacs23, Phillip Lord, 2015/08/04
- [elpa] externals/dash f0dd4cc 301/426: Add -annotate, Phillip Lord, 2015/08/04
- [elpa] externals/dash b44140a 288/426: Add -is-prefix/suffix/infix-p,
Phillip Lord <=
- [elpa] externals/dash 38ef86e 376/426: Update debug forms for -if-let and -when-let, Phillip Lord, 2015/08/04
- [elpa] externals/dash b308794 416/426: [Fix #73] Add a mention of -filter to -keep docstring, Phillip Lord, 2015/08/04
- [elpa] externals/dash 9642c4a 385/426: [Fix #108] Sync indentation of threading forms with Clojure, Phillip Lord, 2015/08/04
- [elpa] externals/dash 0384eee 312/426: Improve Travis CI configuration, Phillip Lord, 2015/08/04
- [elpa] externals/dash 6abc35a 277/426: Merge pull request #66 from rejeep/each-indent-level, Phillip Lord, 2015/08/04
- [elpa] externals/dash 5f879b3 387/426: Merge pull request #110 from bbatsov/comment-fix, Phillip Lord, 2015/08/04
- [elpa] externals/dash 8530742 410/426: Add @wasamasa and @occidens to list of contributors, Phillip Lord, 2015/08/04
- [elpa] externals/dash a803dd5 414/426: Merge readme changes, Phillip Lord, 2015/08/04
- [elpa] externals/dash 1d4881f 413/426: Update README, Phillip Lord, 2015/08/04
- [elpa] externals/dash b075846 287/426: Add -iterate, -unfold, Phillip Lord, 2015/08/04