[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/dash a9f90d7 016/316: Add -select-column(s)
From: |
ELPA Syncer |
Subject: |
[elpa] externals/dash a9f90d7 016/316: Add -select-column(s) |
Date: |
Mon, 15 Feb 2021 15:57:16 -0500 (EST) |
branch: externals/dash
commit a9f90d7834337dadee1a69f2089e39fd81b22ba7
Author: Matus Goljer <matus.goljer@gmail.com>
Commit: Matus Goljer <matus.goljer@gmail.com>
Add -select-column(s)
---
README.md | 35 +++++++++++++++++++++++++++++++++++
dash.el | 25 +++++++++++++++++++++++++
dev/examples.el | 10 +++++++++-
3 files changed, 69 insertions(+), 1 deletion(-)
diff --git a/README.md b/README.md
index 453b5ab..04e14e5 100644
--- a/README.md
+++ b/README.md
@@ -103,6 +103,8 @@ Functions returning a sublist of the original list.
* [-take-while](#-take-while-pred-list) `(pred list)`
* [-drop-while](#-drop-while-pred-list) `(pred list)`
* [-select-by-indices](#-select-by-indices-indices-list) `(indices list)`
+* [-select-columns](#-select-columns-columns-table) `(columns table)`
+* [-select-column](#-select-column-column-table) `(column table)`
### List to list
@@ -575,6 +577,39 @@ as `(nth i list)` for all i from `indices`.
(-select-by-indices '(0 1 2 0 1 3 3 1) '("f" "a" "r" "l")) ;; => '("f" "a" "r"
"f" "a" "l" "l" "a")
```
+#### -select-columns `(columns table)`
+
+Select `columns` from `table`.
+
+`table` is a list of lists where each element represents one row.
+It is assumed each row has the same length.
+
+Each row is transformed such that only the specified `columns` are
+selected.
+
+See also: [`-select-column`](#-select-column-column-table),
[`-select-by-indices`](#-select-by-indices-indices-list)
+
+```el
+(-select-columns '(0 2) '((1 2 3) (a b c) (:a :b :c))) ;; => '((1 3) (a c) (:a
:c))
+(-select-columns '(1) '((1 2 3) (a b c) (:a :b :c))) ;; => '((2) (b) (:b))
+(-select-columns nil '((1 2 3) (a b c) (:a :b :c))) ;; => '(nil nil nil)
+```
+
+#### -select-column `(column table)`
+
+Select `column` from `table`.
+
+`table` is a list of lists where each element represents one row.
+It is assumed each row has the same length.
+
+The single selected column is returned as a list.
+
+See also: [`-select-columns`](#-select-columns-columns-table),
[`-select-by-indices`](#-select-by-indices-indices-list)
+
+```el
+(-select-column 1 '((1 2 3) (a b c) (:a :b :c))) ;; => '(2 b :b)
+```
+
## List to list
diff --git a/dash.el b/dash.el
index b799b44..3f20e5c 100644
--- a/dash.el
+++ b/dash.el
@@ -1189,6 +1189,29 @@ as `(nth i list)` for all i from INDICES."
(!cons (nth it list) r))
(nreverse r)))
+(defun -select-columns (columns table)
+ "Select COLUMNS from TABLE.
+
+TABLE is a list of lists where each element represents one row.
+It is assumed each row has the same length.
+
+Each row is transformed such that only the specified COLUMNS are
+selected.
+
+See also: `-select-column', `-select-by-indices'"
+ (--map (-select-by-indices columns it) table))
+
+(defun -select-column (column table)
+ "Select COLUMN from TABLE.
+
+TABLE is a list of lists where each element represents one row.
+It is assumed each row has the same length.
+
+The single selected column is returned as a list.
+
+See also: `-select-columns', `-select-by-indices'"
+ (--mapcat (-select-by-indices (list column) it) table))
+
(defmacro -> (x &optional form &rest more)
"Thread the expr through the forms. Insert X as the second item
in the first form, making a list of it if it is not a list
@@ -2341,6 +2364,8 @@ structure such as plist or alist."
"-find-last-index"
"--find-last-index"
"-select-by-indices"
+ "-select-columns"
+ "-select-column"
"-grade-up"
"-grade-down"
"->"
diff --git a/dev/examples.el b/dev/examples.el
index 22ea314..6377e69 100644
--- a/dev/examples.el
+++ b/dev/examples.el
@@ -179,7 +179,15 @@ new list."
(defexamples -select-by-indices
(-select-by-indices '(4 10 2 3 6) '("v" "e" "l" "o" "c" "i" "r" "a" "p"
"t" "o" "r")) => '("c" "o" "l" "o" "r")
(-select-by-indices '(2 1 0) '("a" "b" "c")) => '("c" "b" "a")
- (-select-by-indices '(0 1 2 0 1 3 3 1) '("f" "a" "r" "l")) => '("f" "a"
"r" "f" "a" "l" "l" "a")))
+ (-select-by-indices '(0 1 2 0 1 3 3 1) '("f" "a" "r" "l")) => '("f" "a"
"r" "f" "a" "l" "l" "a"))
+
+ (defexamples -select-columns
+ (-select-columns '(0 2) '((1 2 3) (a b c) (:a :b :c))) => '((1 3) (a c)
(:a :c))
+ (-select-columns '(1) '((1 2 3) (a b c) (:a :b :c))) => '((2) (b) (:b))
+ (-select-columns nil '((1 2 3) (a b c) (:a :b :c))) => '(nil nil nil))
+
+ (defexamples -select-column
+ (-select-column 1 '((1 2 3) (a b c) (:a :b :c))) => '(2 b :b)))
(def-example-group "List to list"
"Bag of various functions which modify input list."
- [elpa] externals/dash 6ded2f2 014/316: Add 'see also' to `-find-index` and `-find-last-index`., (continued)
- [elpa] externals/dash 6ded2f2 014/316: Add 'see also' to `-find-index` and `-find-last-index`., ELPA Syncer, 2021/02/15
- [elpa] externals/dash e680ad0 015/316: Merge pull request #173 from Wilfred/master, ELPA Syncer, 2021/02/15
- [elpa] externals/dash a10fb6b 028/316: Add -each-indexed keyword to font-lock, ELPA Syncer, 2021/02/15
- [elpa] externals/dash 502be58 029/316: Make -each-indexed indent like -each, ELPA Syncer, 2021/02/15
- [elpa] externals/dash 4ae329a 032/316: Release 2.13.0, ELPA Syncer, 2021/02/15
- [elpa] externals/dash 0100584 033/316: Correct typo of 'does' to 'do' in -map-when docs, ELPA Syncer, 2021/02/15
- [elpa] externals/dash b7ba212 036/316: Edebug support for threading macros (#188), ELPA Syncer, 2021/02/15
- [elpa] externals/dash d4bccfe 037/316: Add annotations to pure functions. (#199), ELPA Syncer, 2021/02/15
- [elpa] externals/dash 4b805e1 041/316: Update README, ELPA Syncer, 2021/02/15
- [elpa] externals/dash bcc74b5 045/316: [#200] Define setters for -first-item and -last-item, ELPA Syncer, 2021/02/15
- [elpa] externals/dash a9f90d7 016/316: Add -select-column(s),
ELPA Syncer <=
- [elpa] externals/dash 27b1ea5 030/316: Update changelog for 2.12.x., ELPA Syncer, 2021/02/15
- [elpa] externals/dash 52e7eb4 031/316: Merge pull request #191 from Wilfred/update_changelog, ELPA Syncer, 2021/02/15
- [elpa] externals/dash 3075aea 040/316: Add -unzip, ELPA Syncer, 2021/02/15
- [elpa] externals/dash 2996a0d 035/316: Add a LICENSE file (#194), ELPA Syncer, 2021/02/15
- [elpa] externals/dash 9dfb01a 050/316: Correct use of eval-after-load, ELPA Syncer, 2021/02/15
- [elpa] externals/dash 75cde71 052/316: Ensure that -first-item is as fast as car, ELPA Syncer, 2021/02/15
- [elpa] externals/dash 05dc0aa 062/316: Add copyright assignment statement to documentation, ELPA Syncer, 2021/02/15
- [elpa] externals/dash 4de2189 027/316: [Feature #185] -cut <> in first slot is a function, ELPA Syncer, 2021/02/15
- [elpa] externals/dash b45b38a 039/316: Fix typo, ELPA Syncer, 2021/02/15
- [elpa] externals/dash 07c61f5 046/316: [#200] Add tests for generalized variables, ELPA Syncer, 2021/02/15