Add -select-column(s)

master
Matus Goljer 10 years ago
parent e680ad0fdb
commit a9f90d7834
  1. 35
      README.md
  2. 25
      dash.el
  3. 10
      dev/examples.el

@ -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

@ -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"
"->"

@ -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."

Loading…
Cancel
Save