My attempt to optimize my emacs load time <1 second
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

3461 lines
117 KiB

  1. This is /Users/leviolson/.emacs.d/straight/build/dash/dash.info,
  2. produced by makeinfo version 4.8 from
  3. /Users/leviolson/.emacs.d/straight/repos/dash.el/dash.texi.
  4. INFO-DIR-SECTION Emacs
  5. START-INFO-DIR-ENTRY
  6. * Dash: (dash.info). A modern list library for GNU Emacs
  7. END-INFO-DIR-ENTRY
  8. This manual is for `dash.el' version 2.12.1.
  9. Copyright © 2012-2015 Magnar Sveen
  10. This program is free software; you can redistribute it and/or
  11. modify it under the terms of the GNU General Public License as
  12. published by the Free Software Foundation, either version 3 of the
  13. License, or (at your option) any later version.
  14. This program is distributed in the hope that it will be useful,
  15. but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. General Public License for more details.
  18. You should have received a copy of the GNU General Public License
  19. along with this program. If not, see
  20. `http://www.gnu.org/licenses/'.
  21. 
  22. File: dash.info, Node: Top, Next: Installation, Up: (dir)
  23. dash
  24. ****
  25. This manual is for `dash.el' version 2.12.1.
  26. Copyright © 2012-2015 Magnar Sveen
  27. This program is free software; you can redistribute it and/or
  28. modify it under the terms of the GNU General Public License as
  29. published by the Free Software Foundation, either version 3 of the
  30. License, or (at your option) any later version.
  31. This program is distributed in the hope that it will be useful,
  32. but WITHOUT ANY WARRANTY; without even the implied warranty of
  33. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  34. General Public License for more details.
  35. You should have received a copy of the GNU General Public License
  36. along with this program. If not, see
  37. `http://www.gnu.org/licenses/'.
  38. * Menu:
  39. * Installation::
  40. * Functions::
  41. * Development::
  42. * Index::
  43. --- The Detailed Node Listing ---
  44. Installation
  45. * Using in a package::
  46. * Syntax highlighting of dash functions::
  47. Functions
  48. * Maps::
  49. * Sublist selection::
  50. * List to list::
  51. * Reductions::
  52. * Unfolding::
  53. * Predicates::
  54. * Partitioning::
  55. * Indexing::
  56. * Set operations::
  57. * Other list operations::
  58. * Tree operations::
  59. * Threading macros::
  60. * Binding::
  61. * Side-effects::
  62. * Destructive operations::
  63. * Function combinators::
  64. Development
  65. * Contribute:: How to contribute
  66. * Changes:: List of significant changes by version
  67. * Contributors:: List of contributors
  68. 
  69. File: dash.info, Node: Installation, Next: Functions, Prev: Top, Up: Top
  70. 1 Installation
  71. **************
  72. It's available on Melpa (https://melpa.org/); use `M-x package-install':
  73. `M-x package-install <RET> dash'
  74. Install the dash library.
  75. `M-x package-install <RET> dash-functional'
  76. Optional, if you want the function combinators.
  77. Alternatively, you can just dump dash.el or dash-functional.el in
  78. your load path somewhere.
  79. * Menu:
  80. * Using in a package::
  81. * Syntax highlighting of dash functions::
  82. 
  83. File: dash.info, Node: Using in a package, Next: Syntax highlighting of dash functions, Up: Installation
  84. 1.1 Using in a package
  85. ======================
  86. Add this to the big comment block at the top:
  87. ;; Package-Requires: ((dash "2.12.1"))
  88. To get function combinators:
  89. ;; Package-Requires: ((dash "2.12.1") (dash-functional "1.2.0") (emacs "24"))
  90. 
  91. File: dash.info, Node: Syntax highlighting of dash functions, Prev: Using in a package, Up: Installation
  92. 1.2 Syntax highlighting of dash functions
  93. =========================================
  94. Font lock of dash functions in emacs lisp buffers is now optional.
  95. Include this in your emacs settings to get syntax highlighting:
  96. (eval-after-load 'dash '(dash-enable-font-lock))
  97. 
  98. File: dash.info, Node: Functions, Next: Development, Prev: Installation, Up: Top
  99. 2 Functions
  100. ***********
  101. This chapter contains reference documentation for the dash application
  102. programming interface (API). All functions and constructs in the
  103. library are prefixed with a dash (-).
  104. There are also anaphoric versions of functions where that makes
  105. sense, prefixed with two dashes instead of one.
  106. For instance, while `-map' takes a function to map over the list,
  107. one can also use the anaphoric form with double dashes - which will
  108. then be executed with `it' exposed as the list item. Here's an example:
  109. (-map (lambda (n) (* n n)) '(1 2 3 4)) ;; normal version
  110. (--map (* it it) '(1 2 3 4)) ;; anaphoric version
  111. Of course, the original can also be written like
  112. (defun square (n) (* n n))
  113. (-map 'square '(1 2 3 4))
  114. which demonstrates the usefulness of both versions.
  115. * Menu:
  116. * Maps::
  117. * Sublist selection::
  118. * List to list::
  119. * Reductions::
  120. * Unfolding::
  121. * Predicates::
  122. * Partitioning::
  123. * Indexing::
  124. * Set operations::
  125. * Other list operations::
  126. * Tree operations::
  127. * Threading macros::
  128. * Binding::
  129. * Side-effects::
  130. * Destructive operations::
  131. * Function combinators::
  132. 
  133. File: dash.info, Node: Maps, Next: Sublist selection, Up: Functions
  134. 2.1 Maps
  135. ========
  136. Functions in this category take a transforming function, which is then
  137. applied sequentially to each or selected elements of the input list.
  138. The results are collected in order and returned as new list.
  139. -- Function: -map (fn list)
  140. Return a new list consisting of the result of applying FN to the
  141. items in LIST.
  142. (-map (lambda (num) (* num num)) '(1 2 3 4))
  143. => '(1 4 9 16)
  144. (-map 'square '(1 2 3 4))
  145. => '(1 4 9 16)
  146. (--map (* it it) '(1 2 3 4))
  147. => '(1 4 9 16)
  148. -- Function: -map-when (pred rep list)
  149. Return a new list where the elements in LIST that do not match the
  150. PRED function are unchanged, and where the elements in LIST that
  151. do match the PRED function are mapped through the REP function.
  152. Alias: `-replace-where'
  153. See also: `-update-at' (*note -update-at::)
  154. (-map-when 'even? 'square '(1 2 3 4))
  155. => '(1 4 3 16)
  156. (--map-when (> it 2) (* it it) '(1 2 3 4))
  157. => '(1 2 9 16)
  158. (--map-when (= it 2) 17 '(1 2 3 4))
  159. => '(1 17 3 4)
  160. -- Function: -map-first (pred rep list)
  161. Replace first item in LIST satisfying PRED with result of REP
  162. called on this item.
  163. See also: `-map-when' (*note -map-when::), `-replace-first' (*note
  164. -replace-first::)
  165. (-map-first 'even? 'square '(1 2 3 4))
  166. => '(1 4 3 4)
  167. (--map-first (> it 2) (* it it) '(1 2 3 4))
  168. => '(1 2 9 4)
  169. (--map-first (= it 2) 17 '(1 2 3 2))
  170. => '(1 17 3 2)
  171. -- Function: -map-last (pred rep list)
  172. Replace last item in LIST satisfying PRED with result of REP
  173. called on this item.
  174. See also: `-map-when' (*note -map-when::), `-replace-last' (*note
  175. -replace-last::)
  176. (-map-last 'even? 'square '(1 2 3 4))
  177. => '(1 2 3 16)
  178. (--map-last (> it 2) (* it it) '(1 2 3 4))
  179. => '(1 2 3 16)
  180. (--map-last (= it 2) 17 '(1 2 3 2))
  181. => '(1 2 3 17)
  182. -- Function: -map-indexed (fn list)
  183. Return a new list consisting of the result of (FN index item) for
  184. each item in LIST.
  185. In the anaphoric form `--map-indexed', the index is exposed as
  186. symbol `it-index'.
  187. See also: `-each-indexed' (*note -each-indexed::).
  188. (-map-indexed (lambda (index item) (- item index)) '(1 2 3 4))
  189. => '(1 1 1 1)
  190. (--map-indexed (- it it-index) '(1 2 3 4))
  191. => '(1 1 1 1)
  192. -- Function: -annotate (fn list)
  193. Return a list of cons cells where each cell is FN applied to each
  194. element of LIST paired with the unmodified element of LIST.
  195. (-annotate '1+ '(1 2 3))
  196. => '((2 . 1) (3 . 2) (4 . 3))
  197. (-annotate 'length '(("h" "e" "l" "l" "o") ("hello" "world")))
  198. => '((5 "h" "e" "l" "l" "o") (2 "hello" "world"))
  199. (--annotate (< 1 it) '(0 1 2 3))
  200. => '((nil . 0) (nil . 1) (t . 2) (t . 3))
  201. -- Function: -splice (pred fun list)
  202. Splice lists generated by FUN in place of elements matching PRED
  203. in LIST.
  204. FUN takes the element matching PRED as input.
  205. This function can be used as replacement for `,@' in case you need
  206. to splice several lists at marked positions (for example with
  207. keywords).
  208. See also: `-splice-list' (*note -splice-list::), `-insert-at'
  209. (*note -insert-at::)
  210. (-splice 'even? (lambda (x) (list x x)) '(1 2 3 4))
  211. => '(1 2 2 3 4 4)
  212. (--splice 't (list it it) '(1 2 3 4))
  213. => '(1 1 2 2 3 3 4 4)
  214. (--splice (equal it :magic) '((list of) (magical) (code)) '((foo) (bar) :magic (baz)))
  215. => '((foo) (bar) (list of) (magical) (code) (baz))
  216. -- Function: -splice-list (pred new-list list)
  217. Splice NEW-LIST in place of elements matching PRED in LIST.
  218. See also: `-splice' (*note -splice::), `-insert-at' (*note
  219. -insert-at::)
  220. (-splice-list 'keywordp '(a b c) '(1 :foo 2))
  221. => '(1 a b c 2)
  222. (-splice-list 'keywordp nil '(1 :foo 2))
  223. => '(1 2)
  224. (--splice-list (keywordp it) '(a b c) '(1 :foo 2))
  225. => '(1 a b c 2)
  226. -- Function: -mapcat (fn list)
  227. Return the concatenation of the result of mapping FN over LIST.
  228. Thus function FN should return a list.
  229. (-mapcat 'list '(1 2 3))
  230. => '(1 2 3)
  231. (-mapcat (lambda (item) (list 0 item)) '(1 2 3))
  232. => '(0 1 0 2 0 3)
  233. (--mapcat (list 0 it) '(1 2 3))
  234. => '(0 1 0 2 0 3)
  235. -- Function: -copy (arg)
  236. Create a shallow copy of LIST.
  237. (fn LIST)
  238. (-copy '(1 2 3))
  239. => '(1 2 3)
  240. (let ((a '(1 2 3))) (eq a (-copy a)))
  241. => nil
  242. 
  243. File: dash.info, Node: Sublist selection, Next: List to list, Prev: Maps, Up: Functions
  244. 2.2 Sublist selection
  245. =====================
  246. Functions returning a sublist of the original list.
  247. -- Function: -filter (pred list)
  248. Return a new list of the items in LIST for which PRED returns a
  249. non-nil value.
  250. Alias: `-select'
  251. See also: `-keep' (*note -keep::), `-remove' (*note -remove::).
  252. (-filter (lambda (num) (= 0 (% num 2))) '(1 2 3 4))
  253. => '(2 4)
  254. (-filter 'even? '(1 2 3 4))
  255. => '(2 4)
  256. (--filter (= 0 (% it 2)) '(1 2 3 4))
  257. => '(2 4)
  258. -- Function: -remove (pred list)
  259. Return a new list of the items in LIST for which PRED returns nil.
  260. Alias: `-reject'
  261. See also: `-filter' (*note -filter::).
  262. (-remove (lambda (num) (= 0 (% num 2))) '(1 2 3 4))
  263. => '(1 3)
  264. (-remove 'even? '(1 2 3 4))
  265. => '(1 3)
  266. (--remove (= 0 (% it 2)) '(1 2 3 4))
  267. => '(1 3)
  268. -- Function: -remove-first (pred list)
  269. Return a new list with the first item matching PRED removed.
  270. Alias: `-reject-first'
  271. See also: `-remove' (*note -remove::), `-map-first' (*note
  272. -map-first::)
  273. (-remove-first 'even? '(1 3 5 4 7 8 10))
  274. => '(1 3 5 7 8 10)
  275. (-remove-first 'stringp '(1 2 "first" "second" "third"))
  276. => '(1 2 "second" "third")
  277. (--remove-first (> it 3) '(1 2 3 4 5 6 7 8 9 10))
  278. => '(1 2 3 5 6 7 8 9 10)
  279. -- Function: -remove-last (pred list)
  280. Return a new list with the last item matching PRED removed.
  281. Alias: `-reject-last'
  282. See also: `-remove' (*note -remove::), `-map-last' (*note
  283. -map-last::)
  284. (-remove-last 'even? '(1 3 5 4 7 8 10 11))
  285. => '(1 3 5 4 7 8 11)
  286. (-remove-last 'stringp '(1 2 "last" "second" "third"))
  287. => '(1 2 "last" "second")
  288. (--remove-last (> it 3) '(1 2 3 4 5 6 7 8 9 10))
  289. => '(1 2 3 4 5 6 7 8 9)
  290. -- Function: -remove-item (item list)
  291. Remove all occurrences of ITEM from LIST.
  292. Comparison is done with `equal'.
  293. (-remove-item 3 '(1 2 3 2 3 4 5 3))
  294. => '(1 2 2 4 5)
  295. (-remove-item 'foo '(foo bar baz foo))
  296. => '(bar baz)
  297. (-remove-item "bob" '("alice" "bob" "eve" "bob" "dave"))
  298. => '("alice" "eve" "dave")
  299. -- Function: -non-nil (list)
  300. Return all non-nil elements of LIST.
  301. (-non-nil '(1 nil 2 nil nil 3 4 nil 5 nil))
  302. => '(1 2 3 4 5)
  303. -- Function: -slice (list from &optional to step)
  304. Return copy of LIST, starting from index FROM to index TO.
  305. FROM or TO may be negative. These values are then interpreted
  306. modulo the length of the list.
  307. If STEP is a number, only each STEPth item in the resulting
  308. section is returned. Defaults to 1.
  309. (-slice '(1 2 3 4 5) 1)
  310. => '(2 3 4 5)
  311. (-slice '(1 2 3 4 5) 0 3)
  312. => '(1 2 3)
  313. (-slice '(1 2 3 4 5 6 7 8 9) 1 -1 2)
  314. => '(2 4 6 8)
  315. -- Function: -take (n list)
  316. Return a new list of the first N items in LIST, or all items if
  317. there are fewer than N.
  318. See also: `-take-last' (*note -take-last::)
  319. (-take 3 '(1 2 3 4 5))
  320. => '(1 2 3)
  321. (-take 17 '(1 2 3 4 5))
  322. => '(1 2 3 4 5)
  323. -- Function: -take-last (n list)
  324. Return the last N items of LIST in order.
  325. See also: `-take' (*note -take::)
  326. (-take-last 3 '(1 2 3 4 5))
  327. => '(3 4 5)
  328. (-take-last 17 '(1 2 3 4 5))
  329. => '(1 2 3 4 5)
  330. (-take-last 1 '(1 2 3 4 5))
  331. => '(5)
  332. -- Function: -drop (n list)
  333. Return the tail of LIST without the first N items.
  334. See also: `-drop-last' (*note -drop-last::)
  335. (fn N LIST)
  336. (-drop 3 '(1 2 3 4 5))
  337. => '(4 5)
  338. (-drop 17 '(1 2 3 4 5))
  339. => '()
  340. -- Function: -drop-last (n list)
  341. Remove the last N items of LIST and return a copy.
  342. See also: `-drop' (*note -drop::)
  343. (-drop-last 3 '(1 2 3 4 5))
  344. => '(1 2)
  345. (-drop-last 17 '(1 2 3 4 5))
  346. => '()
  347. -- Function: -take-while (pred list)
  348. Return a new list of successive items from LIST while (PRED item)
  349. returns a non-nil value.
  350. (-take-while 'even? '(1 2 3 4))
  351. => '()
  352. (-take-while 'even? '(2 4 5 6))
  353. => '(2 4)
  354. (--take-while (< it 4) '(1 2 3 4 3 2 1))
  355. => '(1 2 3)
  356. -- Function: -drop-while (pred list)
  357. Return the tail of LIST starting from the first item for which
  358. (PRED item) returns nil.
  359. (-drop-while 'even? '(1 2 3 4))
  360. => '(1 2 3 4)
  361. (-drop-while 'even? '(2 4 5 6))
  362. => '(5 6)
  363. (--drop-while (< it 4) '(1 2 3 4 3 2 1))
  364. => '(4 3 2 1)
  365. -- Function: -select-by-indices (indices list)
  366. Return a list whose elements are elements from LIST selected as
  367. `(nth i list)` for all i from INDICES.
  368. (-select-by-indices '(4 10 2 3 6) '("v" "e" "l" "o" "c" "i" "r" "a" "p" "t" "o" "r"))
  369. => '("c" "o" "l" "o" "r")
  370. (-select-by-indices '(2 1 0) '("a" "b" "c"))
  371. => '("c" "b" "a")
  372. (-select-by-indices '(0 1 2 0 1 3 3 1) '("f" "a" "r" "l"))
  373. => '("f" "a" "r" "f" "a" "l" "l" "a")
  374. -- Function: -select-columns (columns table)
  375. Select COLUMNS from TABLE.
  376. TABLE is a list of lists where each element represents one row.
  377. It is assumed each row has the same length.
  378. Each row is transformed such that only the specified COLUMNS are
  379. selected.
  380. See also: `-select-column' (*note -select-column::),
  381. `-select-by-indices' (*note -select-by-indices::)
  382. (-select-columns '(0 2) '((1 2 3) (a b c) (:a :b :c)))
  383. => '((1 3) (a c) (:a :c))
  384. (-select-columns '(1) '((1 2 3) (a b c) (:a :b :c)))
  385. => '((2) (b) (:b))
  386. (-select-columns nil '((1 2 3) (a b c) (:a :b :c)))
  387. => '(nil nil nil)
  388. -- Function: -select-column (column table)
  389. Select COLUMN from TABLE.
  390. TABLE is a list of lists where each element represents one row.
  391. It is assumed each row has the same length.
  392. The single selected column is returned as a list.
  393. See also: `-select-columns' (*note -select-columns::),
  394. `-select-by-indices' (*note -select-by-indices::)
  395. (-select-column 1 '((1 2 3) (a b c) (:a :b :c)))
  396. => '(2 b :b)
  397. 
  398. File: dash.info, Node: List to list, Next: Reductions, Prev: Sublist selection, Up: Functions
  399. 2.3 List to list
  400. ================
  401. Functions returning a modified copy of the input list.
  402. -- Function: -keep (fn list)
  403. Return a new list of the non-nil results of applying FN to the
  404. items in LIST.
  405. If you want to select the original items satisfying a predicate
  406. use `-filter' (*note -filter::).
  407. (-keep 'cdr '((1 2 3) (4 5) (6)))
  408. => '((2 3) (5))
  409. (-keep (lambda (num) (when (> num 3) (* 10 num))) '(1 2 3 4 5 6))
  410. => '(40 50 60)
  411. (--keep (when (> it 3) (* 10 it)) '(1 2 3 4 5 6))
  412. => '(40 50 60)
  413. -- Function: -concat (&rest lists)
  414. Return a new list with the concatenation of the elements in the
  415. supplied LISTS.
  416. (-concat '(1))
  417. => '(1)
  418. (-concat '(1) '(2))
  419. => '(1 2)
  420. (-concat '(1) '(2 3) '(4))
  421. => '(1 2 3 4)
  422. -- Function: -flatten (l)
  423. Take a nested list L and return its contents as a single, flat
  424. list.
  425. Note that because `nil' represents a list of zero elements (an
  426. empty list), any mention of nil in L will disappear after
  427. flattening. If you need to preserve nils, consider `-flatten-n'
  428. (*note -flatten-n::) or map them to some unique symbol and then
  429. map them back.
  430. Conses of two atoms are considered "terminals", that is, they
  431. aren't flattened further.
  432. See also: `-flatten-n' (*note -flatten-n::)
  433. (-flatten '((1)))
  434. => '(1)
  435. (-flatten '((1 (2 3) (((4 (5)))))))
  436. => '(1 2 3 4 5)
  437. (-flatten '(1 2 (3 . 4)))
  438. => '(1 2 (3 . 4))
  439. -- Function: -flatten-n (num list)
  440. Flatten NUM levels of a nested LIST.
  441. See also: `-flatten' (*note -flatten::)
  442. (-flatten-n 1 '((1 2) ((3 4) ((5 6)))))
  443. => '(1 2 (3 4) ((5 6)))
  444. (-flatten-n 2 '((1 2) ((3 4) ((5 6)))))
  445. => '(1 2 3 4 (5 6))
  446. (-flatten-n 3 '((1 2) ((3 4) ((5 6)))))
  447. => '(1 2 3 4 5 6)
  448. -- Function: -replace (old new list)
  449. Replace all OLD items in LIST with NEW.
  450. Elements are compared using `equal'.
  451. See also: `-replace-at' (*note -replace-at::)
  452. (-replace 1 "1" '(1 2 3 4 3 2 1))
  453. => '("1" 2 3 4 3 2 "1")
  454. (-replace "foo" "bar" '("a" "nice" "foo" "sentence" "about" "foo"))
  455. => '("a" "nice" "bar" "sentence" "about" "bar")
  456. (-replace 1 2 nil)
  457. => nil
  458. -- Function: -replace-first (old new list)
  459. Replace the first occurrence of OLD with NEW in LIST.
  460. Elements are compared using `equal'.
  461. See also: `-map-first' (*note -map-first::)
  462. (-replace-first 1 "1" '(1 2 3 4 3 2 1))
  463. => '("1" 2 3 4 3 2 1)
  464. (-replace-first "foo" "bar" '("a" "nice" "foo" "sentence" "about" "foo"))
  465. => '("a" "nice" "bar" "sentence" "about" "foo")
  466. (-replace-first 1 2 nil)
  467. => nil
  468. -- Function: -replace-last (old new list)
  469. Replace the last occurrence of OLD with NEW in LIST.
  470. Elements are compared using `equal'.
  471. See also: `-map-last' (*note -map-last::)
  472. (-replace-last 1 "1" '(1 2 3 4 3 2 1))
  473. => '(1 2 3 4 3 2 "1")
  474. (-replace-last "foo" "bar" '("a" "nice" "foo" "sentence" "about" "foo"))
  475. => '("a" "nice" "foo" "sentence" "about" "bar")
  476. (-replace-last 1 2 nil)
  477. => nil
  478. -- Function: -insert-at (n x list)
  479. Return a list with X inserted into LIST at position N.
  480. See also: `-splice' (*note -splice::), `-splice-list' (*note
  481. -splice-list::)
  482. (-insert-at 1 'x '(a b c))
  483. => '(a x b c)
  484. (-insert-at 12 'x '(a b c))
  485. => '(a b c x)
  486. -- Function: -replace-at (n x list)
  487. Return a list with element at Nth position in LIST replaced with X.
  488. See also: `-replace' (*note -replace::)
  489. (-replace-at 0 9 '(0 1 2 3 4 5))
  490. => '(9 1 2 3 4 5)
  491. (-replace-at 1 9 '(0 1 2 3 4 5))
  492. => '(0 9 2 3 4 5)
  493. (-replace-at 4 9 '(0 1 2 3 4 5))
  494. => '(0 1 2 3 9 5)
  495. -- Function: -update-at (n func list)
  496. Return a list with element at Nth position in LIST replaced with
  497. `(func (nth n list))`.
  498. See also: `-map-when' (*note -map-when::)
  499. (-update-at 0 (lambda (x) (+ x 9)) '(0 1 2 3 4 5))
  500. => '(9 1 2 3 4 5)
  501. (-update-at 1 (lambda (x) (+ x 8)) '(0 1 2 3 4 5))
  502. => '(0 9 2 3 4 5)
  503. (--update-at 2 (length it) '("foo" "bar" "baz" "quux"))
  504. => '("foo" "bar" 3 "quux")
  505. -- Function: -remove-at (n list)
  506. Return a list with element at Nth position in LIST removed.
  507. See also: `-remove-at-indices' (*note -remove-at-indices::),
  508. `-remove' (*note -remove::)
  509. (-remove-at 0 '("0" "1" "2" "3" "4" "5"))
  510. => '("1" "2" "3" "4" "5")
  511. (-remove-at 1 '("0" "1" "2" "3" "4" "5"))
  512. => '("0" "2" "3" "4" "5")
  513. (-remove-at 2 '("0" "1" "2" "3" "4" "5"))
  514. => '("0" "1" "3" "4" "5")
  515. -- Function: -remove-at-indices (indices list)
  516. Return a list whose elements are elements from LIST without
  517. elements selected as `(nth i list)` for all i from INDICES.
  518. See also: `-remove-at' (*note -remove-at::), `-remove' (*note
  519. -remove::)
  520. (-remove-at-indices '(0) '("0" "1" "2" "3" "4" "5"))
  521. => '("1" "2" "3" "4" "5")
  522. (-remove-at-indices '(0 2 4) '("0" "1" "2" "3" "4" "5"))
  523. => '("1" "3" "5")
  524. (-remove-at-indices '(0 5) '("0" "1" "2" "3" "4" "5"))
  525. => '("1" "2" "3" "4")
  526. 
  527. File: dash.info, Node: Reductions, Next: Unfolding, Prev: List to list, Up: Functions
  528. 2.4 Reductions
  529. ==============
  530. Functions reducing lists into single value.
  531. -- Function: -reduce-from (fn initial-value list)
  532. Return the result of applying FN to INITIAL-VALUE and the first
  533. item in LIST, then applying FN to that result and the 2nd item,
  534. etc. If LIST contains no items, return INITIAL-VALUE and do not
  535. call FN.
  536. In the anaphoric form `--reduce-from', the accumulated value is
  537. exposed as symbol `acc'.
  538. See also: `-reduce' (*note -reduce::), `-reduce-r' (*note
  539. -reduce-r::)
  540. (-reduce-from '- 10 '(1 2 3))
  541. => 4
  542. (-reduce-from (lambda (memo item) (format "(%s - %d)" memo item)) "10" '(1 2 3))
  543. => "(((10 - 1) - 2) - 3)"
  544. (--reduce-from (concat acc " " it) "START" '("a" "b" "c"))
  545. => "START a b c"
  546. -- Function: -reduce-r-from (fn initial-value list)
  547. Replace conses with FN, nil with INITIAL-VALUE and evaluate the
  548. resulting expression. If LIST is empty, INITIAL-VALUE is returned
  549. and FN is not called.
  550. Note: this function works the same as `-reduce-from' (*note
  551. -reduce-from::) but the operation associates from right instead of
  552. from left.
  553. See also: `-reduce-r' (*note -reduce-r::), `-reduce' (*note
  554. -reduce::)
  555. (-reduce-r-from '- 10 '(1 2 3))
  556. => -8
  557. (-reduce-r-from (lambda (item memo) (format "(%d - %s)" item memo)) "10" '(1 2 3))
  558. => "(1 - (2 - (3 - 10)))"
  559. (--reduce-r-from (concat it " " acc) "END" '("a" "b" "c"))
  560. => "a b c END"
  561. -- Function: -reduce (fn list)
  562. Return the result of applying FN to the first 2 items in LIST,
  563. then applying FN to that result and the 3rd item, etc. If LIST
  564. contains no items, return the result of calling FN with no
  565. arguments. If LIST contains a single item, return that item and do
  566. not call FN.
  567. In the anaphoric form `--reduce', the accumulated value is exposed
  568. as symbol `acc'.
  569. See also: `-reduce-from' (*note -reduce-from::), `-reduce-r'
  570. (*note -reduce-r::)
  571. (-reduce '- '(1 2 3 4))
  572. => -8
  573. (-reduce 'list '(1 2 3 4))
  574. => '(((1 2) 3) 4)
  575. (--reduce (format "%s-%d" acc it) '(1 2 3))
  576. => "1-2-3"
  577. -- Function: -reduce-r (fn list)
  578. Replace conses with FN and evaluate the resulting expression. The
  579. final nil is ignored. If LIST contains no items, return the result
  580. of calling FN with no arguments. If LIST contains a single item,
  581. return that item and do not call FN.
  582. The first argument of FN is the new item, the second is the
  583. accumulated value.
  584. Note: this function works the same as `-reduce' (*note -reduce::)
  585. but the operation associates from right instead of from left.
  586. See also: `-reduce-r-from' (*note -reduce-r-from::), `-reduce'
  587. (*note -reduce::)
  588. (-reduce-r '- '(1 2 3 4))
  589. => -2
  590. (-reduce-r (lambda (item memo) (format "%s-%d" memo item)) '(1 2 3))
  591. => "3-2-1"
  592. (--reduce-r (format "%s-%d" acc it) '(1 2 3))
  593. => "3-2-1"
  594. -- Function: -reductions-from (fn init list)
  595. Return a list of the intermediate values of the reduction.
  596. See `-reduce-from' (*note -reduce-from::) for explanation of the
  597. arguments.
  598. See also: `-reductions' (*note -reductions::), `-reductions-r'
  599. (*note -reductions-r::), `-reduce-r' (*note -reduce-r::)
  600. (-reductions-from (lambda (a i) (format "(%s FN %d)" a i)) "INIT" '(1 2 3 4))
  601. => '("INIT" "(INIT FN 1)" "((INIT FN 1) FN 2)" "(((INIT FN 1) FN 2) FN 3)" "((((INIT FN 1) FN 2) FN 3) FN 4)")
  602. (-reductions-from 'max 0 '(2 1 4 3))
  603. => '(0 2 2 4 4)
  604. (-reductions-from '* 1 '(1 2 3 4))
  605. => '(1 1 2 6 24)
  606. -- Function: -reductions-r-from (fn init list)
  607. Return a list of the intermediate values of the reduction.
  608. See `-reduce-r-from' (*note -reduce-r-from::) for explanation of
  609. the arguments.
  610. See also: `-reductions-r' (*note -reductions-r::), `-reductions'
  611. (*note -reductions::), `-reduce' (*note -reduce::)
  612. (-reductions-r-from (lambda (i a) (format "(%d FN %s)" i a)) "INIT" '(1 2 3 4))
  613. => '("(1 FN (2 FN (3 FN (4 FN INIT))))" "(2 FN (3 FN (4 FN INIT)))" "(3 FN (4 FN INIT))" "(4 FN INIT)" "INIT")
  614. (-reductions-r-from 'max 0 '(2 1 4 3))
  615. => '(4 4 4 3 0)
  616. (-reductions-r-from '* 1 '(1 2 3 4))
  617. => '(24 24 12 4 1)
  618. -- Function: -reductions (fn list)
  619. Return a list of the intermediate values of the reduction.
  620. See `-reduce' (*note -reduce::) for explanation of the arguments.
  621. See also: `-reductions-from' (*note -reductions-from::),
  622. `-reductions-r' (*note -reductions-r::), `-reduce-r' (*note
  623. -reduce-r::)
  624. (-reductions (lambda (a i) (format "(%s FN %d)" a i)) '(1 2 3 4))
  625. => '(1 "(1 FN 2)" "((1 FN 2) FN 3)" "(((1 FN 2) FN 3) FN 4)")
  626. (-reductions '+ '(1 2 3 4))
  627. => '(1 3 6 10)
  628. (-reductions '* '(1 2 3 4))
  629. => '(1 2 6 24)
  630. -- Function: -reductions-r (fn list)
  631. Return a list of the intermediate values of the reduction.
  632. See `-reduce-r' (*note -reduce-r::) for explanation of the
  633. arguments.
  634. See also: `-reductions-r-from' (*note -reductions-r-from::),
  635. `-reductions' (*note -reductions::), `-reduce' (*note -reduce::)
  636. (-reductions-r (lambda (i a) (format "(%d FN %s)" i a)) '(1 2 3 4))
  637. => '("(1 FN (2 FN (3 FN 4)))" "(2 FN (3 FN 4))" "(3 FN 4)" 4)
  638. (-reductions-r '+ '(1 2 3 4))
  639. => '(10 9 7 4)
  640. (-reductions-r '* '(1 2 3 4))
  641. => '(24 24 12 4)
  642. -- Function: -count (pred list)
  643. Counts the number of items in LIST where (PRED item) is non-nil.
  644. (-count 'even? '(1 2 3 4 5))
  645. => 2
  646. (--count (< it 4) '(1 2 3 4))
  647. => 3
  648. -- Function: -sum (list)
  649. Return the sum of LIST.
  650. (-sum '())
  651. => 0
  652. (-sum '(1))
  653. => 1
  654. (-sum '(1 2 3 4))
  655. => 10
  656. -- Function: -running-sum (list)
  657. Return a list with running sums of items in LIST.
  658. LIST must be non-empty.
  659. (-running-sum '(1 2 3 4))
  660. => '(1 3 6 10)
  661. (-running-sum '(1))
  662. => '(1)
  663. (-running-sum '())
  664. => error
  665. -- Function: -product (list)
  666. Return the product of LIST.
  667. (-product '())
  668. => 1
  669. (-product '(1))
  670. => 1
  671. (-product '(1 2 3 4))
  672. => 24
  673. -- Function: -running-product (list)
  674. Return a list with running products of items in LIST.
  675. LIST must be non-empty.
  676. (-running-product '(1 2 3 4))
  677. => '(1 2 6 24)
  678. (-running-product '(1))
  679. => '(1)
  680. (-running-product '())
  681. => error
  682. -- Function: -inits (list)
  683. Return all prefixes of LIST.
  684. (-inits '(1 2 3 4))
  685. => '(nil (1) (1 2) (1 2 3) (1 2 3 4))
  686. (-inits nil)
  687. => '(nil)
  688. (-inits '(1))
  689. => '(nil (1))
  690. -- Function: -tails (list)
  691. Return all suffixes of LIST
  692. (-tails '(1 2 3 4))
  693. => '((1 2 3 4) (2 3 4) (3 4) (4) nil)
  694. (-tails nil)
  695. => '(nil)
  696. (-tails '(1))
  697. => '((1) nil)
  698. -- Function: -common-prefix (&rest lists)
  699. Return the longest common prefix of LISTS.
  700. (-common-prefix '(1))
  701. => '(1)
  702. (-common-prefix '(1 2) '(3 4) '(1 2))
  703. => nil
  704. (-common-prefix '(1 2) '(1 2 3) '(1 2 3 4))
  705. => '(1 2)
  706. -- Function: -common-suffix (&rest lists)
  707. Return the longest common suffix of LISTS.
  708. (-common-suffix '(1))
  709. => '(1)
  710. (-common-suffix '(1 2) '(3 4) '(1 2))
  711. => nil
  712. (-common-suffix '(1 2 3 4) '(2 3 4) '(3 4))
  713. => '(3 4)
  714. -- Function: -min (list)
  715. Return the smallest value from LIST of numbers or markers.
  716. (-min '(0))
  717. => 0
  718. (-min '(3 2 1))
  719. => 1
  720. (-min '(1 2 3))
  721. => 1
  722. -- Function: -min-by (comparator list)
  723. Take a comparison function COMPARATOR and a LIST and return the
  724. least element of the list by the comparison function.
  725. See also combinator `-on' (*note -on::) which can transform the
  726. values before comparing them.
  727. (-min-by '> '(4 3 6 1))
  728. => 1
  729. (--min-by (> (car it) (car other)) '((1 2 3) (2) (3 2)))
  730. => '(1 2 3)
  731. (--min-by (> (length it) (length other)) '((1 2 3) (2) (3 2)))
  732. => '(2)
  733. -- Function: -max (list)
  734. Return the largest value from LIST of numbers or markers.
  735. (-max '(0))
  736. => 0
  737. (-max '(3 2 1))
  738. => 3
  739. (-max '(1 2 3))
  740. => 3
  741. -- Function: -max-by (comparator list)
  742. Take a comparison function COMPARATOR and a LIST and return the
  743. greatest element of the list by the comparison function.
  744. See also combinator `-on' (*note -on::) which can transform the
  745. values before comparing them.
  746. (-max-by '> '(4 3 6 1))
  747. => 6
  748. (--max-by (> (car it) (car other)) '((1 2 3) (2) (3 2)))
  749. => '(3 2)
  750. (--max-by (> (length it) (length other)) '((1 2 3) (2) (3 2)))
  751. => '(1 2 3)
  752. 
  753. File: dash.info, Node: Unfolding, Next: Predicates, Prev: Reductions, Up: Functions
  754. 2.5 Unfolding
  755. =============
  756. Operations dual to reductions, building lists from seed value rather
  757. than consuming a list to produce a single value.
  758. -- Function: -iterate (fun init n)
  759. Return a list of iterated applications of FUN to INIT.
  760. This means a list of form:
  761. (init (fun init) (fun (fun init)) ...)
  762. N is the length of the returned list.
  763. (-iterate '1+ 1 10)
  764. => '(1 2 3 4 5 6 7 8 9 10)
  765. (-iterate (lambda (x) (+ x x)) 2 5)
  766. => '(2 4 8 16 32)
  767. (--iterate (* it it) 2 5)
  768. => '(2 4 16 256 65536)
  769. -- Function: -unfold (fun seed)
  770. Build a list from SEED using FUN.
  771. This is "dual" operation to `-reduce-r' (*note -reduce-r::): while
  772. -reduce-r consumes a list to produce a single value, `-unfold'
  773. (*note -unfold::) takes a seed value and builds a (potentially
  774. infinite!) list.
  775. FUN should return `nil' to stop the generating process, or a cons
  776. (A . B), where A will be prepended to the result and B is the new
  777. seed.
  778. (-unfold (lambda (x) (unless (= x 0) (cons x (1- x)))) 10)
  779. => '(10 9 8 7 6 5 4 3 2 1)
  780. (--unfold (when it (cons it (cdr it))) '(1 2 3 4))
  781. => '((1 2 3 4) (2 3 4) (3 4) (4))
  782. (--unfold (when it (cons it (butlast it))) '(1 2 3 4))
  783. => '((1 2 3 4) (1 2 3) (1 2) (1))
  784. 
  785. File: dash.info, Node: Predicates, Next: Partitioning, Prev: Unfolding, Up: Functions
  786. 2.6 Predicates
  787. ==============
  788. -- Function: -any? (pred list)
  789. Return t if (PRED x) is non-nil for any x in LIST, else nil.
  790. Alias: `-any-p', `-some?', `-some-p'
  791. (-any? 'even? '(1 2 3))
  792. => t
  793. (-any? 'even? '(1 3 5))
  794. => nil
  795. (-any? 'null '(1 3 5))
  796. => nil
  797. -- Function: -all? (pred list)
  798. Return t if (PRED x) is non-nil for all x in LIST, else nil.
  799. Alias: `-all-p', `-every?', `-every-p'
  800. (-all? 'even? '(1 2 3))
  801. => nil
  802. (-all? 'even? '(2 4 6))
  803. => t
  804. (--all? (= 0 (% it 2)) '(2 4 6))
  805. => t
  806. -- Function: -none? (pred list)
  807. Return t if (PRED x) is nil for all x in LIST, else nil.
  808. Alias: `-none-p'
  809. (-none? 'even? '(1 2 3))
  810. => nil
  811. (-none? 'even? '(1 3 5))
  812. => t
  813. (--none? (= 0 (% it 2)) '(1 2 3))
  814. => nil
  815. -- Function: -only-some? (pred list)
  816. Return `t` if at least one item of LIST matches PRED and at least
  817. one item of LIST does not match PRED. Return `nil` both if all
  818. items match the predicate or if none of the items match the
  819. predicate.
  820. Alias: `-only-some-p'
  821. (-only-some? 'even? '(1 2 3))
  822. => t
  823. (-only-some? 'even? '(1 3 5))
  824. => nil
  825. (-only-some? 'even? '(2 4 6))
  826. => nil
  827. -- Function: -contains? (list element)
  828. Return non-nil if LIST contains ELEMENT.
  829. The test for equality is done with `equal', or with `-compare-fn'
  830. if that's non-nil.
  831. Alias: `-contains-p'
  832. (-contains? '(1 2 3) 1)
  833. => t
  834. (-contains? '(1 2 3) 2)
  835. => t
  836. (-contains? '(1 2 3) 4)
  837. => nil
  838. -- Function: -same-items? (list list2)
  839. Return true if LIST and LIST2 has the same items.
  840. The order of the elements in the lists does not matter.
  841. Alias: `-same-items-p'
  842. (-same-items? '(1 2 3) '(1 2 3))
  843. => t
  844. (-same-items? '(1 2 3) '(3 2 1))
  845. => t
  846. (-same-items? '(1 2 3) '(1 2 3 4))
  847. => nil
  848. -- Function: -is-prefix? (prefix list)
  849. Return non-nil if PREFIX is prefix of LIST.
  850. Alias: `-is-prefix-p'
  851. (-is-prefix? '(1 2 3) '(1 2 3 4 5))
  852. => t
  853. (-is-prefix? '(1 2 3 4 5) '(1 2 3))
  854. => nil
  855. (-is-prefix? '(1 3) '(1 2 3 4 5))
  856. => nil
  857. -- Function: -is-suffix? (suffix list)
  858. Return non-nil if SUFFIX is suffix of LIST.
  859. Alias: `-is-suffix-p'
  860. (-is-suffix? '(3 4 5) '(1 2 3 4 5))
  861. => t
  862. (-is-suffix? '(1 2 3 4 5) '(3 4 5))
  863. => nil
  864. (-is-suffix? '(3 5) '(1 2 3 4 5))
  865. => nil
  866. -- Function: -is-infix? (infix list)
  867. Return non-nil if INFIX is infix of LIST.
  868. This operation runs in O(n^2) time
  869. Alias: `-is-infix-p'
  870. (-is-infix? '(1 2 3) '(1 2 3 4 5))
  871. => t
  872. (-is-infix? '(2 3 4) '(1 2 3 4 5))
  873. => t
  874. (-is-infix? '(3 4 5) '(1 2 3 4 5))
  875. => t
  876. 
  877. File: dash.info, Node: Partitioning, Next: Indexing, Prev: Predicates, Up: Functions
  878. 2.7 Partitioning
  879. ================
  880. Functions partitioning the input list into a list of lists.
  881. -- Function: -split-at (n list)
  882. Return a list of ((-take N LIST) (-drop N LIST)), in no more than
  883. one pass through the list.
  884. (-split-at 3 '(1 2 3 4 5))
  885. => '((1 2 3) (4 5))
  886. (-split-at 17 '(1 2 3 4 5))
  887. => '((1 2 3 4 5) nil)
  888. -- Function: -split-with (pred list)
  889. Return a list of ((-take-while PRED LIST) (-drop-while PRED
  890. LIST)), in no more than one pass through the list.
  891. (-split-with 'even? '(1 2 3 4))
  892. => '(nil (1 2 3 4))
  893. (-split-with 'even? '(2 4 5 6))
  894. => '((2 4) (5 6))
  895. (--split-with (< it 4) '(1 2 3 4 3 2 1))
  896. => '((1 2 3) (4 3 2 1))
  897. -- Macro: -split-on (item list)
  898. Split the LIST each time ITEM is found.
  899. Unlike `-partition-by' (*note -partition-by::), the ITEM is
  900. discarded from the results. Empty lists are also removed from the
  901. result.
  902. Comparison is done by `equal'.
  903. See also `-split-when' (*note -split-when::)
  904. (-split-on '| '(Nil | Leaf a | Node [Tree a]))
  905. => '((Nil) (Leaf a) (Node [Tree a]))
  906. (-split-on ':endgroup '("a" "b" :endgroup "c" :endgroup "d" "e"))
  907. => '(("a" "b") ("c") ("d" "e"))
  908. (-split-on ':endgroup '("a" "b" :endgroup :endgroup "d" "e"))
  909. => '(("a" "b") ("d" "e"))
  910. -- Function: -split-when (fn list)
  911. Split the LIST on each element where FN returns non-nil.
  912. Unlike `-partition-by' (*note -partition-by::), the "matched"
  913. element is discarded from the results. Empty lists are also
  914. removed from the result.
  915. This function can be thought of as a generalization of
  916. `split-string'.
  917. (-split-when 'even? '(1 2 3 4 5 6))
  918. => '((1) (3) (5))
  919. (-split-when 'even? '(1 2 3 4 6 8 9))
  920. => '((1) (3) (9))
  921. (--split-when (memq it '(&optional &rest)) '(a b &optional c d &rest args))
  922. => '((a b) (c d) (args))
  923. -- Function: -separate (pred list)
  924. Return a list of ((-filter PRED LIST) (-remove PRED LIST)), in one
  925. pass through the list.
  926. (-separate (lambda (num) (= 0 (% num 2))) '(1 2 3 4 5 6 7))
  927. => '((2 4 6) (1 3 5 7))
  928. (--separate (< it 5) '(3 7 5 9 3 2 1 4 6))
  929. => '((3 3 2 1 4) (7 5 9 6))
  930. (-separate 'cdr '((1 2) (1) (1 2 3) (4)))
  931. => '(((1 2) (1 2 3)) ((1) (4)))
  932. -- Function: -partition (n list)
  933. Return a new list with the items in LIST grouped into N-sized
  934. sublists. If there are not enough items to make the last group
  935. N-sized, those items are discarded.
  936. (-partition 2 '(1 2 3 4 5 6))
  937. => '((1 2) (3 4) (5 6))
  938. (-partition 2 '(1 2 3 4 5 6 7))
  939. => '((1 2) (3 4) (5 6))
  940. (-partition 3 '(1 2 3 4 5 6 7))
  941. => '((1 2 3) (4 5 6))
  942. -- Function: -partition-all (n list)
  943. Return a new list with the items in LIST grouped into N-sized
  944. sublists. The last group may contain less than N items.
  945. (-partition-all 2 '(1 2 3 4 5 6))
  946. => '((1 2) (3 4) (5 6))
  947. (-partition-all 2 '(1 2 3 4 5 6 7))
  948. => '((1 2) (3 4) (5 6) (7))
  949. (-partition-all 3 '(1 2 3 4 5 6 7))
  950. => '((1 2 3) (4 5 6) (7))
  951. -- Function: -partition-in-steps (n step list)
  952. Return a new list with the items in LIST grouped into N-sized
  953. sublists at offsets STEP apart. If there are not enough items to
  954. make the last group N-sized, those items are discarded.
  955. (-partition-in-steps 2 1 '(1 2 3 4))
  956. => '((1 2) (2 3) (3 4))
  957. (-partition-in-steps 3 2 '(1 2 3 4))
  958. => '((1 2 3))
  959. (-partition-in-steps 3 2 '(1 2 3 4 5))
  960. => '((1 2 3) (3 4 5))
  961. -- Function: -partition-all-in-steps (n step list)
  962. Return a new list with the items in LIST grouped into N-sized
  963. sublists at offsets STEP apart. The last groups may contain less
  964. than N items.
  965. (-partition-all-in-steps 2 1 '(1 2 3 4))
  966. => '((1 2) (2 3) (3 4) (4))
  967. (-partition-all-in-steps 3 2 '(1 2 3 4))
  968. => '((1 2 3) (3 4))
  969. (-partition-all-in-steps 3 2 '(1 2 3 4 5))
  970. => '((1 2 3) (3 4 5) (5))
  971. -- Function: -partition-by (fn list)
  972. Apply FN to each item in LIST, splitting it each time FN returns a
  973. new value.
  974. (-partition-by 'even? '())
  975. => '()
  976. (-partition-by 'even? '(1 1 2 2 2 3 4 6 8))
  977. => '((1 1) (2 2 2) (3) (4 6 8))
  978. (--partition-by (< it 3) '(1 2 3 4 3 2 1))
  979. => '((1 2) (3 4 3) (2 1))
  980. -- Function: -partition-by-header (fn list)
  981. Apply FN to the first item in LIST. That is the header value.
  982. Apply FN to each item in LIST, splitting it each time FN returns
  983. the header value, but only after seeing at least one other value
  984. (the body).
  985. (--partition-by-header (= it 1) '(1 2 3 1 2 1 2 3 4))
  986. => '((1 2 3) (1 2) (1 2 3 4))
  987. (--partition-by-header (> it 0) '(1 2 0 1 0 1 2 3 0))
  988. => '((1 2 0) (1 0) (1 2 3 0))
  989. (-partition-by-header 'even? '(2 1 1 1 4 1 3 5 6 6 1))
  990. => '((2 1 1 1) (4 1 3 5) (6 6 1))
  991. -- Function: -partition-after-pred (pred list)
  992. Partition directly after each time PRED is true on an element of
  993. LIST.
  994. (-partition-after-pred #'odd? '())
  995. => '()
  996. (-partition-after-pred #'odd? '(1))
  997. => '((1))
  998. (-partition-after-pred #'odd? '(0 1))
  999. => '((0 1))
  1000. -- Function: -partition-before-pred (pred list)
  1001. Partition directly before each time PRED is true on an element of
  1002. LIST.
  1003. (-partition-before-pred #'odd? '())
  1004. => '()
  1005. (-partition-before-pred #'odd? '(1))
  1006. => '((1))
  1007. (-partition-before-pred #'odd? '(0 1))
  1008. => '((0) (1))
  1009. -- Function: -partition-before-item (item list)
  1010. Partition directly before each time ITEM appears in LIST.
  1011. (-partition-before-item 3 '())
  1012. => '()
  1013. (-partition-before-item 3 '(1))
  1014. => '((1))
  1015. (-partition-before-item 3 '(3))
  1016. => '((3))
  1017. -- Function: -partition-after-item (item list)
  1018. Partition directly after each time ITEM appears in LIST.
  1019. (-partition-after-item 3 '())
  1020. => '()
  1021. (-partition-after-item 3 '(1))
  1022. => '((1))
  1023. (-partition-after-item 3 '(3))
  1024. => '((3))
  1025. -- Function: -group-by (fn list)
  1026. Separate LIST into an alist whose keys are FN applied to the
  1027. elements of LIST. Keys are compared by `equal'.
  1028. (-group-by 'even? '())
  1029. => '()
  1030. (-group-by 'even? '(1 1 2 2 2 3 4 6 8))
  1031. => '((nil 1 1 3) (t 2 2 2 4 6 8))
  1032. (--group-by (car (split-string it "/")) '("a/b" "c/d" "a/e"))
  1033. => '(("a" "a/b" "a/e") ("c" "c/d"))
  1034. 
  1035. File: dash.info, Node: Indexing, Next: Set operations, Prev: Partitioning, Up: Functions
  1036. 2.8 Indexing
  1037. ============
  1038. Return indices of elements based on predicates, sort elements by
  1039. indices etc.
  1040. -- Function: -elem-index (elem list)
  1041. Return the index of the first element in the given LIST which is
  1042. equal to the query element ELEM, or nil if there is no such
  1043. element.
  1044. (-elem-index 2 '(6 7 8 2 3 4))
  1045. => 3
  1046. (-elem-index "bar" '("foo" "bar" "baz"))
  1047. => 1
  1048. (-elem-index '(1 2) '((3) (5 6) (1 2) nil))
  1049. => 2
  1050. -- Function: -elem-indices (elem list)
  1051. Return the indices of all elements in LIST equal to the query
  1052. element ELEM, in ascending order.
  1053. (-elem-indices 2 '(6 7 8 2 3 4 2 1))
  1054. => '(3 6)
  1055. (-elem-indices "bar" '("foo" "bar" "baz"))
  1056. => '(1)
  1057. (-elem-indices '(1 2) '((3) (1 2) (5 6) (1 2) nil))
  1058. => '(1 3)
  1059. -- Function: -find-index (pred list)
  1060. Take a predicate PRED and a LIST and return the index of the first
  1061. element in the list satisfying the predicate, or nil if there is
  1062. no such element.
  1063. See also `-first' (*note -first::).
  1064. (-find-index 'even? '(2 4 1 6 3 3 5 8))
  1065. => 0
  1066. (--find-index (< 5 it) '(2 4 1 6 3 3 5 8))
  1067. => 3
  1068. (-find-index (-partial 'string-lessp "baz") '("bar" "foo" "baz"))
  1069. => 1
  1070. -- Function: -find-last-index (pred list)
  1071. Take a predicate PRED and a LIST and return the index of the last
  1072. element in the list satisfying the predicate, or nil if there is
  1073. no such element.
  1074. See also `-last' (*note -last::).
  1075. (-find-last-index 'even? '(2 4 1 6 3 3 5 8))
  1076. => 7
  1077. (--find-last-index (< 5 it) '(2 7 1 6 3 8 5 2))
  1078. => 5
  1079. (-find-last-index (-partial 'string-lessp "baz") '("q" "foo" "baz"))
  1080. => 1
  1081. -- Function: -find-indices (pred list)
  1082. Return the indices of all elements in LIST satisfying the
  1083. predicate PRED, in ascending order.
  1084. (-find-indices 'even? '(2 4 1 6 3 3 5 8))
  1085. => '(0 1 3 7)
  1086. (--find-indices (< 5 it) '(2 4 1 6 3 3 5 8))
  1087. => '(3 7)
  1088. (-find-indices (-partial 'string-lessp "baz") '("bar" "foo" "baz"))
  1089. => '(1)
  1090. -- Function: -grade-up (comparator list)
  1091. Grade elements of LIST using COMPARATOR relation, yielding a
  1092. permutation vector such that applying this permutation to LIST
  1093. sorts it in ascending order.
  1094. (-grade-up '< '(3 1 4 2 1 3 3))
  1095. => '(1 4 3 0 5 6 2)
  1096. (let ((l '(3 1 4 2 1 3 3))) (-select-by-indices (-grade-up '< l) l))
  1097. => '(1 1 2 3 3 3 4)
  1098. -- Function: -grade-down (comparator list)
  1099. Grade elements of LIST using COMPARATOR relation, yielding a
  1100. permutation vector such that applying this permutation to LIST
  1101. sorts it in descending order.
  1102. (-grade-down '< '(3 1 4 2 1 3 3))
  1103. => '(2 0 5 6 3 1 4)
  1104. (let ((l '(3 1 4 2 1 3 3))) (-select-by-indices (-grade-down '< l) l))
  1105. => '(4 3 3 3 2 1 1)
  1106. 
  1107. File: dash.info, Node: Set operations, Next: Other list operations, Prev: Indexing, Up: Functions
  1108. 2.9 Set operations
  1109. ==================
  1110. Operations pretending lists are sets.
  1111. -- Function: -union (list list2)
  1112. Return a new list containing the elements of LIST and elements of
  1113. LIST2 that are not in LIST. The test for equality is done with
  1114. `equal', or with `-compare-fn' if that's non-nil.
  1115. (-union '(1 2 3) '(3 4 5))
  1116. => '(1 2 3 4 5)
  1117. (-union '(1 2 3 4) '())
  1118. => '(1 2 3 4)
  1119. (-union '(1 1 2 2) '(3 2 1))
  1120. => '(1 1 2 2 3)
  1121. -- Function: -difference (list list2)
  1122. Return a new list with only the members of LIST that are not in
  1123. LIST2. The test for equality is done with `equal', or with
  1124. `-compare-fn' if that's non-nil.
  1125. (-difference '() '())
  1126. => '()
  1127. (-difference '(1 2 3) '(4 5 6))
  1128. => '(1 2 3)
  1129. (-difference '(1 2 3 4) '(3 4 5 6))
  1130. => '(1 2)
  1131. -- Function: -intersection (list list2)
  1132. Return a new list containing only the elements that are members of
  1133. both LIST and LIST2. The test for equality is done with `equal',
  1134. or with `-compare-fn' if that's non-nil.
  1135. (-intersection '() '())
  1136. => '()
  1137. (-intersection '(1 2 3) '(4 5 6))
  1138. => '()
  1139. (-intersection '(1 2 3 4) '(3 4 5 6))
  1140. => '(3 4)
  1141. -- Function: -powerset (list)
  1142. Return the power set of LIST.
  1143. (-powerset '())
  1144. => '(nil)
  1145. (-powerset '(x y z))
  1146. => '((x y z) (x y) (x z) (x) (y z) (y) (z) nil)
  1147. -- Function: -permutations (list)
  1148. Return the permutations of LIST.
  1149. (-permutations '())
  1150. => '(nil)
  1151. (-permutations '(1 2))
  1152. => '((1 2) (2 1))
  1153. (-permutations '(a b c))
  1154. => '((a b c) (a c b) (b a c) (b c a) (c a b) (c b a))
  1155. -- Function: -distinct (list)
  1156. Return a new list with all duplicates removed. The test for
  1157. equality is done with `equal', or with `-compare-fn' if that's
  1158. non-nil.
  1159. Alias: `-uniq'
  1160. (-distinct '())
  1161. => '()
  1162. (-distinct '(1 2 2 4))
  1163. => '(1 2 4)
  1164. (-distinct '(t t t))
  1165. => '(t)
  1166. 
  1167. File: dash.info, Node: Other list operations, Next: Tree operations, Prev: Set operations, Up: Functions
  1168. 2.10 Other list operations
  1169. ==========================
  1170. Other list functions not fit to be classified elsewhere.
  1171. -- Function: -rotate (n list)
  1172. Rotate LIST N places to the right. With N negative, rotate to the
  1173. left. The time complexity is O(n).
  1174. (-rotate 3 '(1 2 3 4 5 6 7))
  1175. => '(5 6 7 1 2 3 4)
  1176. (-rotate -3 '(1 2 3 4 5 6 7))
  1177. => '(4 5 6 7 1 2 3)
  1178. (-rotate 16 '(1 2 3 4 5 6 7))
  1179. => '(6 7 1 2 3 4 5)
  1180. -- Function: -repeat (n x)
  1181. Return a list with X repeated N times. Return nil if N is less
  1182. than 1.
  1183. (-repeat 3 :a)
  1184. => '(:a :a :a)
  1185. (-repeat 1 :a)
  1186. => '(:a)
  1187. (-repeat 0 :a)
  1188. => nil
  1189. -- Function: -cons* (&rest args)
  1190. Make a new list from the elements of ARGS.
  1191. The last 2 members of ARGS are used as the final cons of the
  1192. result so if the final member of ARGS is not a list the result is
  1193. a dotted list.
  1194. (-cons* 1 2)
  1195. => '(1 . 2)
  1196. (-cons* 1 2 3)
  1197. => '(1 2 . 3)
  1198. (-cons* 1)
  1199. => 1
  1200. -- Function: -snoc (list elem &rest elements)
  1201. Append ELEM to the end of the list.
  1202. This is like `cons', but operates on the end of list.
  1203. If ELEMENTS is non nil, append these to the list as well.
  1204. (-snoc '(1 2 3) 4)
  1205. => '(1 2 3 4)
  1206. (-snoc '(1 2 3) 4 5 6)
  1207. => '(1 2 3 4 5 6)
  1208. (-snoc '(1 2 3) '(4 5 6))
  1209. => '(1 2 3 (4 5 6))
  1210. -- Function: -interpose (sep list)
  1211. Return a new list of all elements in LIST separated by SEP.
  1212. (-interpose "-" '())
  1213. => '()
  1214. (-interpose "-" '("a"))
  1215. => '("a")
  1216. (-interpose "-" '("a" "b" "c"))
  1217. => '("a" "-" "b" "-" "c")
  1218. -- Function: -interleave (&rest lists)
  1219. Return a new list of the first item in each list, then the second
  1220. etc.
  1221. (-interleave '(1 2) '("a" "b"))
  1222. => '(1 "a" 2 "b")
  1223. (-interleave '(1 2) '("a" "b") '("A" "B"))
  1224. => '(1 "a" "A" 2 "b" "B")
  1225. (-interleave '(1 2 3) '("a" "b"))
  1226. => '(1 "a" 2 "b")
  1227. -- Function: -zip-with (fn list1 list2)
  1228. Zip the two lists LIST1 and LIST2 using a function FN. This
  1229. function is applied pairwise taking as first argument element of
  1230. LIST1 and as second argument element of LIST2 at corresponding
  1231. position.
  1232. The anaphoric form `--zip-with' binds the elements from LIST1 as
  1233. symbol `it', and the elements from LIST2 as symbol `other'.
  1234. (-zip-with '+ '(1 2 3) '(4 5 6))
  1235. => '(5 7 9)
  1236. (-zip-with 'cons '(1 2 3) '(4 5 6))
  1237. => '((1 . 4) (2 . 5) (3 . 6))
  1238. (--zip-with (concat it " and " other) '("Batman" "Jekyll") '("Robin" "Hyde"))
  1239. => '("Batman and Robin" "Jekyll and Hyde")
  1240. -- Function: -zip (&rest lists)
  1241. Zip LISTS together. Group the head of each list, followed by the
  1242. second elements of each list, and so on. The lengths of the
  1243. returned groupings are equal to the length of the shortest input
  1244. list.
  1245. If two lists are provided as arguments, return the groupings as a
  1246. list of cons cells. Otherwise, return the groupings as a list of
  1247. lists.
  1248. Use `-zip-lists' (*note -zip-lists::) if you need the return value
  1249. to always be a list of lists.
  1250. Alias: `-zip-pair'
  1251. See also: `-zip-lists' (*note -zip-lists::)
  1252. (-zip '(1 2 3) '(4 5 6))
  1253. => '((1 . 4) (2 . 5) (3 . 6))
  1254. (-zip '(1 2 3) '(4 5 6 7))
  1255. => '((1 . 4) (2 . 5) (3 . 6))
  1256. (-zip '(1 2) '(3 4 5) '(6))
  1257. => '((1 3 6))
  1258. -- Function: -zip-lists (&rest lists)
  1259. Zip LISTS together. Group the head of each list, followed by the
  1260. second elements of each list, and so on. The lengths of the
  1261. returned groupings are equal to the length of the shortest input
  1262. list.
  1263. The return value is always list of lists, which is a difference
  1264. from `-zip-pair' which returns a cons-cell in case two input lists
  1265. are provided.
  1266. See also: `-zip' (*note -zip::)
  1267. (-zip-lists '(1 2 3) '(4 5 6))
  1268. => '((1 4) (2 5) (3 6))
  1269. (-zip-lists '(1 2 3) '(4 5 6 7))
  1270. => '((1 4) (2 5) (3 6))
  1271. (-zip-lists '(1 2) '(3 4 5) '(6))
  1272. => '((1 3 6))
  1273. -- Function: -zip-fill (fill-value &rest lists)
  1274. Zip LISTS, with FILL-VALUE padded onto the shorter lists. The
  1275. lengths of the returned groupings are equal to the length of the
  1276. longest input list.
  1277. (-zip-fill 0 '(1 2 3 4 5) '(6 7 8 9))
  1278. => '((1 . 6) (2 . 7) (3 . 8) (4 . 9) (5 . 0))
  1279. -- Function: -unzip (lists)
  1280. Unzip LISTS.
  1281. This works just like `-zip' (*note -zip::) but takes a list of
  1282. lists instead of a variable number of arguments, such that
  1283. (-unzip (-zip L1 L2 L3 ...))
  1284. is identity (given that the lists are the same length).
  1285. Note in particular that calling this on a list of two lists will
  1286. return a list of cons-cells such that the aboce identity works.
  1287. See also: `-zip' (*note -zip::)
  1288. (-unzip (-zip '(1 2 3) '(a b c) '("e" "f" "g")))
  1289. => '((1 2 3) (a b c) ("e" "f" "g"))
  1290. (-unzip '((1 2) (3 4) (5 6) (7 8) (9 10)))
  1291. => '((1 3 5 7 9) (2 4 6 8 10))
  1292. (-unzip '((1 2) (3 4)))
  1293. => '((1 . 3) (2 . 4))
  1294. -- Function: -cycle (list)
  1295. Return an infinite copy of LIST that will cycle through the
  1296. elements and repeat from the beginning.
  1297. (-take 5 (-cycle '(1 2 3)))
  1298. => '(1 2 3 1 2)
  1299. (-take 7 (-cycle '(1 "and" 3)))
  1300. => '(1 "and" 3 1 "and" 3 1)
  1301. (-zip (-cycle '(1 2 3)) '(1 2))
  1302. => '((1 . 1) (2 . 2))
  1303. -- Function: -pad (fill-value &rest lists)
  1304. Appends FILL-VALUE to the end of each list in LISTS such that they
  1305. will all have the same length.
  1306. (-pad 0 '())
  1307. => '(nil)
  1308. (-pad 0 '(1))
  1309. => '((1))
  1310. (-pad 0 '(1 2 3) '(4 5))
  1311. => '((1 2 3) (4 5 0))
  1312. -- Function: -table (fn &rest lists)
  1313. Compute outer product of LISTS using function FN.
  1314. The function FN should have the same arity as the number of
  1315. supplied lists.
  1316. The outer product is computed by applying fn to all possible
  1317. combinations created by taking one element from each list in
  1318. order. The dimension of the result is (length lists).
  1319. See also: `-table-flat' (*note -table-flat::)
  1320. (-table '* '(1 2 3) '(1 2 3))
  1321. => '((1 2 3) (2 4 6) (3 6 9))
  1322. (-table (lambda (a b) (-sum (-zip-with '* a b))) '((1 2) (3 4)) '((1 3) (2 4)))
  1323. => '((7 15) (10 22))
  1324. (apply '-table 'list (-repeat 3 '(1 2)))
  1325. => '((((1 1 1) (2 1 1)) ((1 2 1) (2 2 1))) (((1 1 2) (2 1 2)) ((1 2 2) (2 2 2))))
  1326. -- Function: -table-flat (fn &rest lists)
  1327. Compute flat outer product of LISTS using function FN.
  1328. The function FN should have the same arity as the number of
  1329. supplied lists.
  1330. The outer product is computed by applying fn to all possible
  1331. combinations created by taking one element from each list in
  1332. order. The results are flattened, ignoring the tensor structure
  1333. of the result. This is equivalent to calling:
  1334. (-flatten-n (1- (length lists)) (apply '-table fn lists))
  1335. but the implementation here is much more efficient.
  1336. See also: `-flatten-n' (*note -flatten-n::), `-table' (*note
  1337. -table::)
  1338. (-table-flat 'list '(1 2 3) '(a b c))
  1339. => '((1 a) (2 a) (3 a) (1 b) (2 b) (3 b) (1 c) (2 c) (3 c))
  1340. (-table-flat '* '(1 2 3) '(1 2 3))
  1341. => '(1 2 3 2 4 6 3 6 9)
  1342. (apply '-table-flat 'list (-repeat 3 '(1 2)))
  1343. => '((1 1 1) (2 1 1) (1 2 1) (2 2 1) (1 1 2) (2 1 2) (1 2 2) (2 2 2))
  1344. -- Function: -first (pred list)
  1345. Return the first x in LIST where (PRED x) is non-nil, else nil.
  1346. To get the first item in the list no questions asked, use `car'.
  1347. Alias: `-find'
  1348. (-first 'even? '(1 2 3))
  1349. => 2
  1350. (-first 'even? '(1 3 5))
  1351. => nil
  1352. (-first 'null '(1 3 5))
  1353. => nil
  1354. -- Function: -some (pred list)
  1355. Return (PRED x) for the first LIST item where (PRED x) is non-nil,
  1356. else nil.
  1357. Alias: `-any'
  1358. (-some 'even? '(1 2 3))
  1359. => t
  1360. (-some 'null '(1 2 3))
  1361. => nil
  1362. (-some 'null '(1 2 nil))
  1363. => t
  1364. -- Function: -last (pred list)
  1365. Return the last x in LIST where (PRED x) is non-nil, else nil.
  1366. (-last 'even? '(1 2 3 4 5 6 3 3 3))
  1367. => 6
  1368. (-last 'even? '(1 3 7 5 9))
  1369. => nil
  1370. (--last (> (length it) 3) '("a" "looong" "word" "and" "short" "one"))
  1371. => "short"
  1372. -- Function: -first-item (list)
  1373. Return the first item of LIST, or nil on an empty list.
  1374. See also: `-second-item' (*note -second-item::), `-last-item'
  1375. (*note -last-item::).
  1376. (fn LIST)
  1377. (-first-item '(1 2 3))
  1378. => 1
  1379. (-first-item nil)
  1380. => nil
  1381. (let ((list (list 1 2 3))) (setf (-first-item list) 5) list)
  1382. => '(5 2 3)
  1383. -- Function: -second-item (arg1)
  1384. Return the second item of LIST, or nil if LIST is too short.
  1385. See also: `-third-item' (*note -third-item::).
  1386. (fn LIST)
  1387. (-second-item '(1 2 3))
  1388. => 2
  1389. (-second-item nil)
  1390. => nil
  1391. -- Function: -third-item (arg1)
  1392. Return the third item of LIST, or nil if LIST is too short.
  1393. See also: `-fourth-item' (*note -fourth-item::).
  1394. (fn LIST)
  1395. (-third-item '(1 2 3))
  1396. => 3
  1397. (-third-item nil)
  1398. => nil
  1399. -- Function: -fourth-item (list)
  1400. Return the fourth item of LIST, or nil if LIST is too short.
  1401. See also: `-fifth-item' (*note -fifth-item::).
  1402. (-fourth-item '(1 2 3 4))
  1403. => 4
  1404. (-fourth-item nil)
  1405. => nil
  1406. -- Function: -fifth-item (list)
  1407. Return the fifth item of LIST, or nil if LIST is too short.
  1408. See also: `-last-item' (*note -last-item::).
  1409. (-fifth-item '(1 2 3 4 5))
  1410. => 5
  1411. (-fifth-item nil)
  1412. => nil
  1413. -- Function: -last-item (list)
  1414. Return the last item of LIST, or nil on an empty list.
  1415. (-last-item '(1 2 3))
  1416. => 3
  1417. (-last-item nil)
  1418. => nil
  1419. (let ((list (list 1 2 3))) (setf (-last-item list) 5) list)
  1420. => '(1 2 5)
  1421. -- Function: -butlast (list)
  1422. Return a list of all items in list except for the last.
  1423. (-butlast '(1 2 3))
  1424. => '(1 2)
  1425. (-butlast '(1 2))
  1426. => '(1)
  1427. (-butlast '(1))
  1428. => nil
  1429. -- Function: -sort (comparator list)
  1430. Sort LIST, stably, comparing elements using COMPARATOR. Return
  1431. the sorted list. LIST is NOT modified by side effects.
  1432. COMPARATOR is called with two elements of LIST, and should return
  1433. non-nil if the first element should sort before the second.
  1434. (-sort '< '(3 1 2))
  1435. => '(1 2 3)
  1436. (-sort '> '(3 1 2))
  1437. => '(3 2 1)
  1438. (--sort (< it other) '(3 1 2))
  1439. => '(1 2 3)
  1440. -- Function: -list (&rest args)
  1441. Return a list with ARGS.
  1442. If first item of ARGS is already a list, simply return ARGS. If
  1443. not, return a list with ARGS as elements.
  1444. (-list 1)
  1445. => '(1)
  1446. (-list 1 2 3)
  1447. => '(1 2 3)
  1448. (-list '(1 2 3))
  1449. => '(1 2 3)
  1450. -- Function: -fix (fn list)
  1451. Compute the (least) fixpoint of FN with initial input LIST.
  1452. FN is called at least once, results are compared with `equal'.
  1453. (-fix (lambda (l) (-non-nil (--mapcat (-split-at (/ (length it) 2) it) l))) '((1 2 3 4 5 6)))
  1454. => '((1) (2) (3) (4) (5) (6))
  1455. (let ((data '(("starwars" "scifi") ("jedi" "starwars" "warrior")))) (--fix (-uniq (--mapcat (cons it (cdr (assoc it data))) it)) '("jedi" "book")))
  1456. => '("jedi" "starwars" "warrior" "scifi" "book")
  1457. 
  1458. File: dash.info, Node: Tree operations, Next: Threading macros, Prev: Other list operations, Up: Functions
  1459. 2.11 Tree operations
  1460. ====================
  1461. Functions pretending lists are trees.
  1462. -- Function: -tree-seq (branch children tree)
  1463. Return a sequence of the nodes in TREE, in depth-first search
  1464. order.
  1465. BRANCH is a predicate of one argument that returns non-nil if the
  1466. passed argument is a branch, that is, a node that can have
  1467. children.
  1468. CHILDREN is a function of one argument that returns the children
  1469. of the passed branch node.
  1470. Non-branch nodes are simply copied.
  1471. (-tree-seq 'listp 'identity '(1 (2 3) 4 (5 (6 7))))
  1472. => '((1 (2 3) 4 (5 (6 7))) 1 (2 3) 2 3 4 (5 (6 7)) 5 (6 7) 6 7)
  1473. (-tree-seq 'listp 'reverse '(1 (2 3) 4 (5 (6 7))))
  1474. => '((1 (2 3) 4 (5 (6 7))) (5 (6 7)) (6 7) 7 6 5 4 (2 3) 3 2 1)
  1475. (--tree-seq (vectorp it) (append it nil) [1 [2 3] 4 [5 [6 7]]])
  1476. => '([1 [2 3] 4 [5 [6 7]]] 1 [2 3] 2 3 4 [5 [6 7]] 5 [6 7] 6 7)
  1477. -- Function: -tree-map (fn tree)
  1478. Apply FN to each element of TREE while preserving the tree
  1479. structure.
  1480. (-tree-map '1+ '(1 (2 3) (4 (5 6) 7)))
  1481. => '(2 (3 4) (5 (6 7) 8))
  1482. (-tree-map '(lambda (x) (cons x (expt 2 x))) '(1 (2 3) 4))
  1483. => '((1 . 2) ((2 . 4) (3 . 8)) (4 . 16))
  1484. (--tree-map (length it) '("<body>" ("<p>" "text" "</p>") "</body>"))
  1485. => '(6 (3 4 4) 7)
  1486. -- Function: -tree-map-nodes (pred fun tree)
  1487. Call FUN on each node of TREE that satisfies PRED.
  1488. If PRED returns nil, continue descending down this node. If PRED
  1489. returns non-nil, apply FUN to this node and do not descend further.
  1490. (-tree-map-nodes 'vectorp (lambda (x) (-sum (append x nil))) '(1 [2 3] 4 (5 [6 7] 8)))
  1491. => '(1 5 4 (5 13 8))
  1492. (-tree-map-nodes 'keywordp (lambda (x) (symbol-name x)) '(1 :foo 4 ((5 6 :bar) :baz 8)))
  1493. => '(1 ":foo" 4 ((5 6 ":bar") ":baz" 8))
  1494. (--tree-map-nodes (eq (car-safe it) 'add-mode) (-concat it (list :mode 'emacs-lisp-mode)) '(with-mode emacs-lisp-mode (foo bar) (add-mode a b) (baz (add-mode c d))))
  1495. => '(with-mode emacs-lisp-mode (foo bar) (add-mode a b :mode emacs-lisp-mode) (baz (add-mode c d :mode emacs-lisp-mode)))
  1496. -- Function: -tree-reduce (fn tree)
  1497. Use FN to reduce elements of list TREE. If elements of TREE are
  1498. lists themselves, apply the reduction recursively.
  1499. FN is first applied to first element of the list and second
  1500. element, then on this result and third element from the list etc.
  1501. See `-reduce-r' (*note -reduce-r::) for how exactly are lists of
  1502. zero or one element handled.
  1503. (-tree-reduce '+ '(1 (2 3) (4 5)))
  1504. => 15
  1505. (-tree-reduce 'concat '("strings" (" on" " various") ((" levels"))))
  1506. => "strings on various levels"
  1507. (--tree-reduce (cond ((stringp it) (concat it " " acc)) (t (let ((sn (symbol-name it))) (concat "<" sn ">" acc "</" sn ">")))) '(body (p "some words") (div "more" (b "bold") "words")))
  1508. => "<body><p>some words</p> <div>more <b>bold</b> words</div></body>"
  1509. -- Function: -tree-reduce-from (fn init-value tree)
  1510. Use FN to reduce elements of list TREE. If elements of TREE are
  1511. lists themselves, apply the reduction recursively.
  1512. FN is first applied to INIT-VALUE and first element of the list,
  1513. then on this result and second element from the list etc.
  1514. The initial value is ignored on cons pairs as they always contain
  1515. two elements.
  1516. (-tree-reduce-from '+ 1 '(1 (1 1) ((1))))
  1517. => 8
  1518. (--tree-reduce-from (-concat acc (list it)) nil '(1 (2 3 (4 5)) (6 7)))
  1519. => '((7 6) ((5 4) 3 2) 1)
  1520. -- Function: -tree-mapreduce (fn folder tree)
  1521. Apply FN to each element of TREE, and make a list of the results.
  1522. If elements of TREE are lists themselves, apply FN recursively to
  1523. elements of these nested lists.
  1524. Then reduce the resulting lists using FOLDER and initial value
  1525. INIT-VALUE. See `-reduce-r-from' (*note -reduce-r-from::).
  1526. This is the same as calling `-tree-reduce' (*note -tree-reduce::)
  1527. after `-tree-map' (*note -tree-map::) but is twice as fast as it
  1528. only traverse the structure once.
  1529. (-tree-mapreduce 'list 'append '(1 (2 (3 4) (5 6)) (7 (8 9))))
  1530. => '(1 2 3 4 5 6 7 8 9)
  1531. (--tree-mapreduce 1 (+ it acc) '(1 (2 (4 9) (2 1)) (7 (4 3))))
  1532. => 9
  1533. (--tree-mapreduce 0 (max acc (1+ it)) '(1 (2 (4 9) (2 1)) (7 (4 3))))
  1534. => 3
  1535. -- Function: -tree-mapreduce-from (fn folder init-value tree)
  1536. Apply FN to each element of TREE, and make a list of the results.
  1537. If elements of TREE are lists themselves, apply FN recursively to
  1538. elements of these nested lists.
  1539. Then reduce the resulting lists using FOLDER and initial value
  1540. INIT-VALUE. See `-reduce-r-from' (*note -reduce-r-from::).
  1541. This is the same as calling `-tree-reduce-from' (*note
  1542. -tree-reduce-from::) after `-tree-map' (*note -tree-map::) but is
  1543. twice as fast as it only traverse the structure once.
  1544. (-tree-mapreduce-from 'identity '* 1 '(1 (2 (3 4) (5 6)) (7 (8 9))))
  1545. => 362880
  1546. (--tree-mapreduce-from (+ it it) (cons it acc) nil '(1 (2 (4 9) (2 1)) (7 (4 3))))
  1547. => '(2 (4 (8 18) (4 2)) (14 (8 6)))
  1548. (concat "{" (--tree-mapreduce-from (cond ((-cons-pair? it) (concat (symbol-name (car it)) " -> " (symbol-name (cdr it)))) (t (concat (symbol-name it) " : {"))) (concat it (unless (or (equal acc "}") (equal (substring it (1- (length it))) "{")) ", ") acc) "}" '((elips-mode (foo (bar . booze)) (baz . qux)) (c-mode (foo . bla) (bum . bam)))))
  1549. => "{elips-mode : {foo : {bar -> booze{, baz -> qux{, c-mode : {foo -> bla, bum -> bam}}"
  1550. -- Function: -clone (list)
  1551. Create a deep copy of LIST. The new list has the same elements
  1552. and structure but all cons are replaced with new ones. This is
  1553. useful when you need to clone a structure such as plist or alist.
  1554. (let* ((a '(1 2 3)) (b (-clone a))) (nreverse a) b)
  1555. => '(1 2 3)
  1556. 
  1557. File: dash.info, Node: Threading macros, Next: Binding, Prev: Tree operations, Up: Functions
  1558. 2.12 Threading macros
  1559. =====================
  1560. -- Macro: -> (x &optional form &rest more)
  1561. Thread the expr through the forms. Insert X as the second item in
  1562. the first form, making a list of it if it is not a list already.
  1563. If there are more forms, insert the first form as the second item
  1564. in second form, etc.
  1565. (-> '(2 3 5))
  1566. => '(2 3 5)
  1567. (-> '(2 3 5) (append '(8 13)))
  1568. => '(2 3 5 8 13)
  1569. (-> '(2 3 5) (append '(8 13)) (-slice 1 -1))
  1570. => '(3 5 8)
  1571. -- Macro: ->> (x &optional form &rest more)
  1572. Thread the expr through the forms. Insert X as the last item in
  1573. the first form, making a list of it if it is not a list already.
  1574. If there are more forms, insert the first form as the last item in
  1575. second form, etc.
  1576. (->> '(1 2 3) (-map 'square))
  1577. => '(1 4 9)
  1578. (->> '(1 2 3) (-map 'square) (-remove 'even?))
  1579. => '(1 9)
  1580. (->> '(1 2 3) (-map 'square) (-reduce '+))
  1581. => 14
  1582. -- Macro: -> (x &rest forms)
  1583. Starting with the value of X, thread each expression through FORMS.
  1584. Insert X at the position signified by the symbol `it' in the first
  1585. form. If there are more forms, insert the first form at the
  1586. position signified by `it' in in second form, etc.
  1587. (--> "def" (concat "abc" it "ghi"))
  1588. => "abcdefghi"
  1589. (--> "def" (concat "abc" it "ghi") (upcase it))
  1590. => "ABCDEFGHI"
  1591. (--> "def" (concat "abc" it "ghi") upcase)
  1592. => "ABCDEFGHI"
  1593. -- Macro: -as-> (value variable &rest forms)
  1594. Starting with VALUE, thread VARIABLE through FORMS.
  1595. In the first form, bind VARIABLE to VALUE. In the second form,
  1596. bind VARIABLE to the result of the first form, and so forth.
  1597. (-as-> 3 my-var (1+ my-var) (list my-var) (mapcar (lambda (ele) (* 2 ele)) my-var))
  1598. => '(8)
  1599. (-as-> 3 my-var 1+)
  1600. => 4
  1601. (-as-> 3 my-var)
  1602. => 3
  1603. -- Macro: -some-> (x &optional form &rest more)
  1604. When expr is non-nil, thread it through the first form (via `->'
  1605. (*note ->::)), and when that result is non-nil, through the next
  1606. form, etc.
  1607. (-some-> '(2 3 5))
  1608. => '(2 3 5)
  1609. (-some-> 5 square)
  1610. => 25
  1611. (-some-> 5 even? square)
  1612. => nil
  1613. -- Macro: -some->> (x &optional form &rest more)
  1614. When expr is non-nil, thread it through the first form (via `->>'
  1615. (*note ->>::)), and when that result is non-nil, through the next
  1616. form, etc.
  1617. (-some->> '(1 2 3) (-map 'square))
  1618. => '(1 4 9)
  1619. (-some->> '(1 3 5) (-last 'even?) (+ 100))
  1620. => nil
  1621. (-some->> '(2 4 6) (-last 'even?) (+ 100))
  1622. => 106
  1623. -- Macro: -some-> (x &optional form &rest more)
  1624. When expr in non-nil, thread it through the first form (via `-->'
  1625. (*note -->::)), and when that result is non-nil, through the next
  1626. form, etc.
  1627. (-some--> "def" (concat "abc" it "ghi"))
  1628. => "abcdefghi"
  1629. (-some--> nil (concat "abc" it "ghi"))
  1630. => nil
  1631. (-some--> '(1 3 5) (-filter 'even? it) (append it it) (-map 'square it))
  1632. => nil
  1633. 
  1634. File: dash.info, Node: Binding, Next: Side-effects, Prev: Threading macros, Up: Functions
  1635. 2.13 Binding
  1636. ============
  1637. Convenient versions of `let` and `let*` constructs combined with flow
  1638. control.
  1639. -- Macro: -when-let (var-val &rest body)
  1640. If VAL evaluates to non-nil, bind it to VAR and execute body.
  1641. Note: binding is done according to `-let' (*note -let::).
  1642. (fn (VAR VAL) &rest BODY)
  1643. (-when-let (match-index (string-match "d" "abcd")) (+ match-index 2))
  1644. => 5
  1645. (-when-let ((&plist :foo foo) (list :foo "foo")) foo)
  1646. => "foo"
  1647. (-when-let ((&plist :foo foo) (list :bar "bar")) foo)
  1648. => nil
  1649. -- Macro: -when-let* (vars-vals &rest body)
  1650. If all VALS evaluate to true, bind them to their corresponding
  1651. VARS and execute body. VARS-VALS should be a list of (VAR VAL)
  1652. pairs.
  1653. Note: binding is done according to `-let*' (*note -let*::). VALS
  1654. are evaluated sequentially, and evaluation stops after the first
  1655. nil VAL is encountered.
  1656. (-when-let* ((x 5) (y 3) (z (+ y 4))) (+ x y z))
  1657. => 15
  1658. (-when-let* ((x 5) (y nil) (z 7)) (+ x y z))
  1659. => nil
  1660. -- Macro: -if-let (var-val then &rest else)
  1661. If VAL evaluates to non-nil, bind it to VAR and do THEN, otherwise
  1662. do ELSE.
  1663. Note: binding is done according to `-let' (*note -let::).
  1664. (fn (VAR VAL) THEN &rest ELSE)
  1665. (-if-let (match-index (string-match "d" "abc")) (+ match-index 3) 7)
  1666. => 7
  1667. (--if-let (even? 4) it nil)
  1668. => t
  1669. -- Macro: -if-let* (vars-vals then &rest else)
  1670. If all VALS evaluate to true, bind them to their corresponding
  1671. VARS and do THEN, otherwise do ELSE. VARS-VALS should be a list of
  1672. (VAR VAL) pairs.
  1673. Note: binding is done according to `-let*' (*note -let*::). VALS
  1674. are evaluated sequentially, and evaluation stops after the first
  1675. nil VAL is encountered.
  1676. (-if-let* ((x 5) (y 3) (z 7)) (+ x y z) "foo")
  1677. => 15
  1678. (-if-let* ((x 5) (y nil) (z 7)) (+ x y z) "foo")
  1679. => "foo"
  1680. (-if-let* (((_ _ x) '(nil nil 7))) x)
  1681. => 7
  1682. -- Macro: -let (varlist &rest body)
  1683. Bind variables according to VARLIST then eval BODY.
  1684. VARLIST is a list of lists of the form (PATTERN SOURCE). Each
  1685. PATTERN is matched against the SOURCE "structurally". SOURCE is
  1686. only evaluated once for each PATTERN. Each PATTERN is matched
  1687. recursively, and can therefore contain sub-patterns which are
  1688. matched against corresponding sub-expressions of SOURCE.
  1689. All the SOURCEs are evalled before any symbols are bound (i.e. "in
  1690. parallel").
  1691. If VARLIST only contains one (PATTERN SOURCE) element, you can
  1692. optionally specify it using a vector and discarding the outer-most
  1693. parens. Thus
  1694. (-let ((PATTERN SOURCE)) ..)
  1695. becomes
  1696. (-let [PATTERN SOURCE] ..).
  1697. `-let' (*note -let::) uses a convention of not binding places
  1698. (symbols) starting with _ whenever it's possible. You can use
  1699. this to skip over entries you don't care about. However, this is
  1700. not *always* possible (as a result of implementation) and these
  1701. symbols might get bound to undefined values.
  1702. Following is the overview of supported patterns. Remember that
  1703. patterns can be matched recursively, so every a, b, aK in the
  1704. following can be a matching construct and not necessarily a
  1705. symbol/variable.
  1706. Symbol:
  1707. a - bind the SOURCE to A. This is just like regular `let'.
  1708. Conses and lists:
  1709. (a) - bind `car' of cons/list to A
  1710. (a . b) - bind car of cons to A and `cdr' to B
  1711. (a b) - bind car of list to A and `cadr' to B
  1712. (a1 a2 a3 ...) - bind 0th car of list to A1, 1st to A2, 2nd to A3
  1713. ...
  1714. (a1 a2 a3 ... aN . rest) - as above, but bind the Nth cdr to REST.
  1715. Vectors:
  1716. [a] - bind 0th element of a non-list sequence to A (works with
  1717. vectors, strings, bit arrays...)
  1718. [a1 a2 a3 ...] - bind 0th element of non-list sequence to A0, 1st
  1719. to A1, 2nd to A2, ...
  1720. If the PATTERN is shorter than SOURCE, the values at
  1721. places not in PATTERN are ignored. If
  1722. the PATTERN is longer than SOURCE, an `error' is
  1723. thrown.
  1724. [a1 a2 a3 ... &rest rest] - as above, but bind the rest of
  1725. the sequence to REST. This is
  1726. conceptually the same as improper list
  1727. matching (a1 a2 ... aN . rest)
  1728. Key/value stores:
  1729. (&plist key0 a0 ... keyN aN) - bind value mapped by keyK in the
  1730. SOURCE plist to aK. If the
  1731. value is not found, aK is nil.
  1732. Uses `plist-get' to fetch values.
  1733. (&alist key0 a0 ... keyN aN) - bind value mapped by keyK in the
  1734. SOURCE alist to aK. If the
  1735. value is not found, aK is nil.
  1736. Uses `assoc' to fetch values.
  1737. (&hash key0 a0 ... keyN aN) - bind value mapped by keyK in the
  1738. SOURCE hash table to aK. If the
  1739. value is not found, aK is nil.
  1740. Uses `gethash' to fetch values.
  1741. Further, special keyword &keys supports "inline" matching of
  1742. plist-like key-value pairs, similarly to &keys keyword of
  1743. `cl-defun'.
  1744. (a1 a2 ... aN &keys key1 b1 ... keyN bK)
  1745. This binds N values from the list to a1 ... aN, then interprets
  1746. the cdr as a plist (see key/value matching above).
  1747. A shorthand notation for kv-destructuring exists which allows the
  1748. patterns be optionally left out and derived from the key name in
  1749. the following fashion:
  1750. - a key :foo is converted into `foo' pattern, - a key 'bar is
  1751. converted into `bar' pattern, - a key "baz" is converted into
  1752. `baz' pattern.
  1753. That is, the entire value under the key is bound to the derived
  1754. variable without any further destructuring.
  1755. This is possible only when the form following the key is not a
  1756. valid pattern (i.e. not a symbol, a cons cell or a vector).
  1757. Otherwise the matching proceeds as usual and in case of an invalid
  1758. spec fails with an error.
  1759. Thus the patterns are normalized as follows:
  1760. ;; derive all the missing patterns (&plist :foo 'bar "baz")
  1761. => (&plist :foo foo 'bar bar "baz" baz)
  1762. ;; we can specify some but not others (&plist :foo 'bar
  1763. explicit-bar) => (&plist :foo foo 'bar explicit-bar)
  1764. ;; nothing happens, we store :foo in x (&plist :foo x) =>
  1765. (&plist :foo x)
  1766. ;; nothing happens, we match recursively (&plist :foo (a b
  1767. c)) => (&plist :foo (a b c))
  1768. You can name the source using the syntax SYMBOL &as PATTERN. This
  1769. syntax works with lists (proper or improper), vectors and all
  1770. types of maps.
  1771. (list &as a b c) (list 1 2 3)
  1772. binds A to 1, B to 2, C to 3 and LIST to (1 2 3).
  1773. Similarly:
  1774. (bounds &as beg . end) (cons 1 2)
  1775. binds BEG to 1, END to 2 and BOUNDS to (1 . 2).
  1776. (items &as first . rest) (list 1 2 3)
  1777. binds FIRST to 1, REST to (2 3) and ITEMS to (1 2 3)
  1778. [vect &as _ b c] [1 2 3]
  1779. binds B to 2, C to 3 and VECT to [1 2 3] (_ avoids binding as
  1780. usual).
  1781. (plist &as &plist :b b) (list :a 1 :b 2 :c 3)
  1782. binds B to 2 and PLIST to (:a 1 :b 2 :c 3). Same for &alist and
  1783. &hash.
  1784. This is especially useful when we want to capture the result of a
  1785. computation and destructure at the same time. Consider the form
  1786. (function-returning-complex-structure) returning a list of two
  1787. vectors with two items each. We want to capture this entire
  1788. result and pass it to another computation, but at the same time we
  1789. want to get the second item from each vector. We can achieve it
  1790. with pattern
  1791. (result &as [_ a] [_ b]) (function-returning-complex-structure)
  1792. Note: Clojure programmers may know this feature as the ":as
  1793. binding". The difference is that we put the &as at the front
  1794. because we need to support improper list binding.
  1795. (-let (([a (b c) d] [1 (2 3) 4])) (list a b c d))
  1796. => '(1 2 3 4)
  1797. (-let [(a b c . d) (list 1 2 3 4 5 6)] (list a b c d))
  1798. => '(1 2 3 (4 5 6))
  1799. (-let [(&plist :foo foo :bar bar) (list :baz 3 :foo 1 :qux 4 :bar 2)] (list foo bar))
  1800. => '(1 2)
  1801. -- Macro: -let* (varlist &rest body)
  1802. Bind variables according to VARLIST then eval BODY.
  1803. VARLIST is a list of lists of the form (PATTERN SOURCE). Each
  1804. PATTERN is matched against the SOURCE structurally. SOURCE is
  1805. only evaluated once for each PATTERN.
  1806. Each SOURCE can refer to the symbols already bound by this
  1807. VARLIST. This is useful if you want to destructure SOURCE
  1808. recursively but also want to name the intermediate structures.
  1809. See `-let' (*note -let::) for the list of all possible patterns.
  1810. (-let* (((a . b) (cons 1 2)) ((c . d) (cons 3 4))) (list a b c d))
  1811. => '(1 2 3 4)
  1812. (-let* (((a . b) (cons 1 (cons 2 3))) ((c . d) b)) (list a b c d))
  1813. => '(1 (2 . 3) 2 3)
  1814. (-let* (((&alist "foo" foo "bar" bar) (list (cons "foo" 1) (cons "bar" (list 'a 'b 'c)))) ((a b c) bar)) (list foo a b c bar))
  1815. => '(1 a b c (a b c))
  1816. -- Macro: -lambda (match-form &rest body)
  1817. Return a lambda which destructures its input as MATCH-FORM and
  1818. executes BODY.
  1819. Note that you have to enclose the MATCH-FORM in a pair of parens,
  1820. such that:
  1821. (-lambda (x) body) (-lambda (x y ...) body)
  1822. has the usual semantics of `lambda'. Furthermore, these get
  1823. translated into normal lambda, so there is no performance penalty.
  1824. See `-let' (*note -let::) for the description of destructuring
  1825. mechanism.
  1826. (-map (-lambda ((x y)) (+ x y)) '((1 2) (3 4) (5 6)))
  1827. => '(3 7 11)
  1828. (-map (-lambda ([x y]) (+ x y)) '([1 2] [3 4] [5 6]))
  1829. => '(3 7 11)
  1830. (funcall (-lambda ((_ . a) (_ . b)) (-concat a b)) '(1 2 3) '(4 5 6))
  1831. => '(2 3 5 6)
  1832. -- Macro: -setq (&rest forms)
  1833. Bind each MATCH-FORM to the value of its VAL.
  1834. MATCH-FORM destructuring is done according to the rules of `-let'
  1835. (*note -let::).
  1836. This macro allows you to bind multiple variables by destructuring
  1837. the value, so for example:
  1838. (-setq (a b) x (&plist :c c) plist)
  1839. expands roughly speaking to the following code
  1840. (setq a (car x) b (cadr x) c (plist-get plist
  1841. :c))
  1842. Care is taken to only evaluate each VAL once so that in case of
  1843. multiple assignments it does not cause unexpected side effects.
  1844. (fn [MATCH-FORM VAL]...)
  1845. (progn (-setq a 1) a)
  1846. => 1
  1847. (progn (-setq (a b) (list 1 2)) (list a b))
  1848. => '(1 2)
  1849. (progn (-setq (&plist :c c) (list :c "c")) c)
  1850. => "c"
  1851. 
  1852. File: dash.info, Node: Side-effects, Next: Destructive operations, Prev: Binding, Up: Functions
  1853. 2.14 Side-effects
  1854. =================
  1855. Functions iterating over lists for side-effect only.
  1856. -- Function: -each (list fn)
  1857. Call FN with every item in LIST. Return nil, used for side-effects
  1858. only.
  1859. (let (s) (-each '(1 2 3) (lambda (item) (setq s (cons item s)))))
  1860. => nil
  1861. (let (s) (-each '(1 2 3) (lambda (item) (setq s (cons item s)))) s)
  1862. => '(3 2 1)
  1863. (let (s) (--each '(1 2 3) (setq s (cons it s))) s)
  1864. => '(3 2 1)
  1865. -- Function: -each-while (list pred fn)
  1866. Call FN with every item in LIST while (PRED item) is non-nil.
  1867. Return nil, used for side-effects only.
  1868. (let (s) (-each-while '(2 4 5 6) 'even? (lambda (item) (!cons item s))) s)
  1869. => '(4 2)
  1870. (let (s) (--each-while '(1 2 3 4) (< it 3) (!cons it s)) s)
  1871. => '(2 1)
  1872. -- Function: -each-indexed (list fn)
  1873. Call (FN index item) for each item in LIST.
  1874. In the anaphoric form `--each-indexed', the index is exposed as
  1875. symbol `it-index'.
  1876. See also: `-map-indexed' (*note -map-indexed::).
  1877. (let (s) (-each-indexed '(a b c) (lambda (index item) (setq s (cons (list item index) s)))) s)
  1878. => '((c 2) (b 1) (a 0))
  1879. (let (s) (--each-indexed '(a b c) (setq s (cons (list it it-index) s))) s)
  1880. => '((c 2) (b 1) (a 0))
  1881. -- Function: -each-r (list fn)
  1882. Call FN with every item in LIST in reversed order. Return nil,
  1883. used for side-effects only.
  1884. (let (s) (-each-r '(1 2 3) (lambda (item) (setq s (cons item s)))))
  1885. => nil
  1886. (let (s) (-each-r '(1 2 3) (lambda (item) (setq s (cons item s)))) s)
  1887. => '(1 2 3)
  1888. (let (s) (--each-r '(1 2 3) (setq s (cons it s))) s)
  1889. => '(1 2 3)
  1890. -- Function: -each-r-while (list pred fn)
  1891. Call FN with every item in reversed LIST while (PRED item) is
  1892. non-nil. Return nil, used for side-effects only.
  1893. (let (s) (-each-r-while '(2 4 5 6) 'even? (lambda (item) (!cons item s))) s)
  1894. => '(6)
  1895. (let (s) (--each-r-while '(1 2 3 4) (>= it 3) (!cons it s)) s)
  1896. => '(3 4)
  1897. -- Function: -dotimes (num fn)
  1898. Repeatedly calls FN (presumably for side-effects) passing in
  1899. integers from 0 through NUM-1.
  1900. (let (s) (-dotimes 3 (lambda (n) (!cons n s))) s)
  1901. => '(2 1 0)
  1902. (let (s) (--dotimes 5 (!cons it s)) s)
  1903. => '(4 3 2 1 0)
  1904. -- Macro: -doto (eval-initial-value &rest forms)
  1905. Eval a form, then insert that form as the 2nd argument to other
  1906. forms. The EVAL-INITIAL-VALUE form is evaluated once. Its result
  1907. is passed to FORMS, which are then evaluated sequentially. Returns
  1908. the target form.
  1909. (-doto '(1 2 3) (!cdr) (!cdr))
  1910. => '(3)
  1911. (-doto '(1 . 2) (setcar 3) (setcdr 4))
  1912. => '(3 . 4)
  1913. -- Macro: -doto (eval-initial-value &rest forms)
  1914. Anaphoric form of `-doto' (*note -doto::). Note: `it' is not
  1915. required in each form.
  1916. (gethash "key" (--doto (make-hash-table :test 'equal) (puthash "key" "value" it)))
  1917. => "value"
  1918. 
  1919. File: dash.info, Node: Destructive operations, Next: Function combinators, Prev: Side-effects, Up: Functions
  1920. 2.15 Destructive operations
  1921. ===========================
  1922. -- Macro: !cons (car cdr)
  1923. Destructive: Set CDR to the cons of CAR and CDR.
  1924. (let (l) (!cons 5 l) l)
  1925. => '(5)
  1926. (let ((l '(3))) (!cons 5 l) l)
  1927. => '(5 3)
  1928. -- Macro: !cdr (list)
  1929. Destructive: Set LIST to the cdr of LIST.
  1930. (let ((l '(3))) (!cdr l) l)
  1931. => '()
  1932. (let ((l '(3 5))) (!cdr l) l)
  1933. => '(5)
  1934. 
  1935. File: dash.info, Node: Function combinators, Prev: Destructive operations, Up: Functions
  1936. 2.16 Function combinators
  1937. =========================
  1938. These combinators require Emacs 24 for its lexical scope. So they are
  1939. offered in a separate package: `dash-functional`.
  1940. -- Function: -partial (fn &rest args)
  1941. Takes a function FN and fewer than the normal arguments to FN, and
  1942. returns a fn that takes a variable number of additional ARGS.
  1943. When called, the returned function calls FN with ARGS first and
  1944. then additional args.
  1945. (funcall (-partial '- 5) 3)
  1946. => 2
  1947. (funcall (-partial '+ 5 2) 3)
  1948. => 10
  1949. -- Function: -rpartial (fn &rest args)
  1950. Takes a function FN and fewer than the normal arguments to FN, and
  1951. returns a fn that takes a variable number of additional ARGS.
  1952. When called, the returned function calls FN with the additional
  1953. args first and then ARGS.
  1954. (funcall (-rpartial '- 5) 8)
  1955. => 3
  1956. (funcall (-rpartial '- 5 2) 10)
  1957. => 3
  1958. -- Function: -juxt (&rest fns)
  1959. Takes a list of functions and returns a fn that is the
  1960. juxtaposition of those fns. The returned fn takes a variable
  1961. number of args, and returns a list containing the result of
  1962. applying each fn to the args (left-to-right).
  1963. (funcall (-juxt '+ '-) 3 5)
  1964. => '(8 -2)
  1965. (-map (-juxt 'identity 'square) '(1 2 3))
  1966. => '((1 1) (2 4) (3 9))
  1967. -- Function: -compose (&rest fns)
  1968. Takes a list of functions and returns a fn that is the composition
  1969. of those fns. The returned fn takes a variable number of
  1970. arguments, and returns the result of applying each fn to the
  1971. result of applying the previous fn to the arguments
  1972. (right-to-left).
  1973. (funcall (-compose 'square '+) 2 3)
  1974. => (square (+ 2 3))
  1975. (funcall (-compose 'identity 'square) 3)
  1976. => (square 3)
  1977. (funcall (-compose 'square 'identity) 3)
  1978. => (square 3)
  1979. -- Function: -applify (fn)
  1980. Changes an n-arity function FN to a 1-arity function that expects
  1981. a list with n items as arguments
  1982. (-map (-applify '+) '((1 1 1) (1 2 3) (5 5 5)))
  1983. => '(3 6 15)
  1984. (-map (-applify (lambda (a b c) `(,a (,b (,c))))) '((1 1 1) (1 2 3) (5 5 5)))
  1985. => '((1 (1 (1))) (1 (2 (3))) (5 (5 (5))))
  1986. (funcall (-applify '<) '(3 6))
  1987. => t
  1988. -- Function: -on (operator transformer)
  1989. Return a function of two arguments that first applies TRANSFORMER
  1990. to each of them and then applies OPERATOR on the results (in the
  1991. same order).
  1992. In types: (b -> b -> c) -> (a -> b) -> a -> a -> c
  1993. (-sort (-on '< 'length) '((1 2 3) (1) (1 2)))
  1994. => '((1) (1 2) (1 2 3))
  1995. (-min-by (-on '> 'length) '((1 2 3) (4) (1 2)))
  1996. => '(4)
  1997. (-min-by (-on 'string-lessp 'number-to-string) '(2 100 22))
  1998. => 22
  1999. -- Function: -flip (func)
  2000. Swap the order of arguments for binary function FUNC.
  2001. In types: (a -> b -> c) -> b -> a -> c
  2002. (funcall (-flip '<) 2 1)
  2003. => t
  2004. (funcall (-flip '-) 3 8)
  2005. => 5
  2006. (-sort (-flip '<) '(4 3 6 1))
  2007. => '(6 4 3 1)
  2008. -- Function: -const (c)
  2009. Return a function that returns C ignoring any additional arguments.
  2010. In types: a -> b -> a
  2011. (funcall (-const 2) 1 3 "foo")
  2012. => 2
  2013. (-map (-const 1) '("a" "b" "c" "d"))
  2014. => '(1 1 1 1)
  2015. (-sum (-map (-const 1) '("a" "b" "c" "d")))
  2016. => 4
  2017. -- Macro: -cut (&rest params)
  2018. Take n-ary function and n arguments and specialize some of them.
  2019. Arguments denoted by <> will be left unspecialized.
  2020. See SRFI-26 for detailed description.
  2021. (funcall (-cut list 1 <> 3 <> 5) 2 4)
  2022. => '(1 2 3 4 5)
  2023. (-map (-cut funcall <> 5) '(1+ 1- (lambda (x) (/ 1.0 x))))
  2024. => '(6 4 0.2)
  2025. (-map (-cut <> 1 2 3) (list 'list 'vector 'string))
  2026. => '((1 2 3) [1 2 3] "")
  2027. -- Function: -not (pred)
  2028. Take a unary predicate PRED and return a unary predicate that
  2029. returns t if PRED returns nil and nil if PRED returns non-nil.
  2030. (funcall (-not 'even?) 5)
  2031. => t
  2032. (-filter (-not (-partial '< 4)) '(1 2 3 4 5 6 7 8))
  2033. => '(1 2 3 4)
  2034. -- Function: -orfn (&rest preds)
  2035. Take list of unary predicates PREDS and return a unary predicate
  2036. with argument x that returns non-nil if at least one of the PREDS
  2037. returns non-nil on x.
  2038. In types: [a -> Bool] -> a -> Bool
  2039. (-filter (-orfn 'even? (-partial (-flip '<) 5)) '(1 2 3 4 5 6 7 8 9 10))
  2040. => '(1 2 3 4 6 8 10)
  2041. (funcall (-orfn 'stringp 'even?) "foo")
  2042. => t
  2043. -- Function: -andfn (&rest preds)
  2044. Take list of unary predicates PREDS and return a unary predicate
  2045. with argument x that returns non-nil if all of the PREDS returns
  2046. non-nil on x.
  2047. In types: [a -> Bool] -> a -> Bool
  2048. (funcall (-andfn (-cut < <> 10) 'even?) 6)
  2049. => t
  2050. (funcall (-andfn (-cut < <> 10) 'even?) 12)
  2051. => nil
  2052. (-filter (-andfn (-not 'even?) (-cut >= 5 <>)) '(1 2 3 4 5 6 7 8 9 10))
  2053. => '(1 3 5)
  2054. -- Function: -iteratefn (fn n)
  2055. Return a function FN composed N times with itself.
  2056. FN is a unary function. If you need to use a function of higher
  2057. arity, use `-applify' (*note -applify::) first to turn it into a
  2058. unary function.
  2059. With n = 0, this acts as identity function.
  2060. In types: (a -> a) -> Int -> a -> a.
  2061. This function satisfies the following law:
  2062. (funcall (-iteratefn fn n) init) = (-last-item (-iterate fn init
  2063. (1+ n))).
  2064. (funcall (-iteratefn (lambda (x) (* x x)) 3) 2)
  2065. => 256
  2066. (funcall (-iteratefn '1+ 3) 1)
  2067. => 4
  2068. (funcall (-iteratefn 'cdr 3) '(1 2 3 4 5))
  2069. => '(4 5)
  2070. -- Function: -fixfn (fn &optional equal-test halt-test)
  2071. Return a function that computes the (least) fixpoint of FN.
  2072. FN must be a unary function. The returned lambda takes a single
  2073. argument, X, the initial value for the fixpoint iteration. The
  2074. iteration halts when either of the following conditions is
  2075. satisfied:
  2076. 1. Iteration converges to the fixpoint, with equality being
  2077. tested using EQUAL-TEST. If EQUAL-TEST is not specified,
  2078. `equal' is used. For functions over the floating point
  2079. numbers, it may be necessary to provide an appropriate
  2080. appoximate comparison test.
  2081. 2. HALT-TEST returns a non-nil value. HALT-TEST defaults to a
  2082. simple counter that returns t after `-fixfn-max-iterations',
  2083. to guard against infinite iteration. Otherwise, HALT-TEST
  2084. must be a function that accepts a single argument, the
  2085. current value of X, and returns non-nil as long as iteration
  2086. should continue. In this way, a more sophisticated
  2087. convergence test may be supplied by the caller.
  2088. The return value of the lambda is either the fixpoint or, if
  2089. iteration halted before converging, a cons with car `halted' and
  2090. cdr the final output from HALT-TEST.
  2091. In types: (a -> a) -> a -> a.
  2092. (funcall (-fixfn 'cos 'approx-equal) 0.7)
  2093. => 0.7390851332151607
  2094. (funcall (-fixfn (lambda (x) (expt (+ x 10) 0.25))) 2.0)
  2095. => 1.8555845286409378
  2096. (funcall (-fixfn 'sin 'approx-equal) 0.1)
  2097. => '(halted . t)
  2098. -- Function: -prodfn (&rest fns)
  2099. Take a list of n functions and return a function that takes a list
  2100. of length n, applying i-th function to i-th element of the input
  2101. list. Returns a list of length n.
  2102. In types (for n=2): ((a -> b), (c -> d)) -> (a, c) -> (b, d)
  2103. This function satisfies the following laws:
  2104. (-compose (-prodfn f g ...) (-prodfn f' g' ...)) = (-prodfn
  2105. (-compose f f') (-compose g g') ...) (-prodfn f g ...) =
  2106. (-juxt (-compose f (-partial 'nth 0)) (-compose g (-partial 'nth
  2107. 1)) ...) (-compose (-prodfn f g ...) (-juxt f' g' ...)) =
  2108. (-juxt (-compose f f') (-compose g g') ...) (-compose
  2109. (-partial 'nth n) (-prod f1 f2 ...)) = (-compose fn (-partial 'nth
  2110. n))
  2111. (funcall (-prodfn '1+ '1- 'number-to-string) '(1 2 3))
  2112. => '(2 1 "3")
  2113. (-map (-prodfn '1+ '1-) '((1 2) (3 4) (5 6) (7 8)))
  2114. => '((2 1) (4 3) (6 5) (8 7))
  2115. (apply '+ (funcall (-prodfn 'length 'string-to-number) '((1 2 3) "15")))
  2116. => 18
  2117. 
  2118. File: dash.info, Node: Development, Next: Index, Prev: Functions, Up: Top
  2119. 3 Development
  2120. *************
  2121. The dash repository is hosted on GitHub:
  2122. `https://github.com/magnars/dash.el'
  2123. * Menu:
  2124. * Contribute:: How to contribute
  2125. * Changes:: List of significant changes by version
  2126. * Contributors:: List of contributors
  2127. 
  2128. File: dash.info, Node: Contribute, Next: Changes, Up: Development
  2129. 3.1 Contribute
  2130. ==============
  2131. Yes, please do. Pure functions in the list manipulation realm only,
  2132. please. There's a suite of tests in dev/examples.el, so remember to add
  2133. tests for your function, or it might get broken later.
  2134. Run the tests with `./run-tests.sh'. Create the docs with
  2135. `./create-docs.sh'. I highly recommend that you install these as a
  2136. pre-commit hook, so that the tests are always running and the docs are
  2137. always in sync:
  2138. cp pre-commit.sh .git/hooks/pre-commit
  2139. Oh, and don't edit `README.md' directly, it is auto-generated.
  2140. Change `readme-template.md' or `examples-to-docs.el' instead. The same
  2141. goes for the info manual.
  2142. 
  2143. File: dash.info, Node: Changes, Next: Contributors, Prev: Contribute, Up: Development
  2144. 3.2 Changes
  2145. ===========
  2146. Changes in 2.10:
  2147. * Add `-let' destructuring to `-if-let' and `-when-let' (Fredrik
  2148. Bergroth)
  2149. Changes in 2.9:
  2150. * Add `-let', `-let*' and `-lambda' with destructuring
  2151. * Add `-tree-seq' and `-tree-map-nodes'
  2152. * Add `-non-nil'
  2153. * Add `-fix'
  2154. * Add `-fixfn' (dash-functional 1.2)
  2155. * Add `-copy' (Wilfred Hughes)
  2156. Changes in 2.8:
  2157. * Add `-butlast'
  2158. Changes in 2.7:
  2159. * `-zip' now supports more than two lists (Steve Lamb)
  2160. * Add `-cycle', `-pad', `-annotate', `-zip-fill' (Steve Lamb)
  2161. * Add `-table', `-table-flat' (finite cartesian product)
  2162. * Add `-flatten-n'
  2163. * `-slice' now supports "step" argument
  2164. * Add functional combinators `-iteratefn', `-prodfn'
  2165. * Add `-replace', `-splice', `-splice-list' which generalize
  2166. `-replace-at' and `-insert-at'
  2167. * Add `-compose', `-iteratefn' and `-prodfn' (dash-functional 1.1)
  2168. Changes in 2.6:
  2169. * Add `-is-prefix-p', `-is-suffix-p', `-is-infix-p' (Matus Goljer)
  2170. * Add `-iterate', `-unfold' (Matus Goljer)
  2171. * Add `-split-on', `-split-when' (Matus Goljer)
  2172. * Add `-find-last-index' (Matus Goljer)
  2173. * Add `-list' (Johan Andersson)
  2174. Changes in 2.5:
  2175. * Add `-same-items?' (Johan Andersson)
  2176. * A few bugfixes
  2177. Changes in 2.4:
  2178. * Add `-snoc' (Matus Goljer)
  2179. * Add `-replace-at', `-update-at', `-remove-at', and
  2180. `-remove-at-indices' (Matus Goljer)
  2181. Changes in 2.3:
  2182. * Add tree operations (Matus Goljer)
  2183. * Make font-lock optional
  2184. Changes in 2.2:
  2185. * Add `-compose' (Christina Whyte)
  2186. Changes in 2.1:
  2187. * Add indexing operations (Matus Goljer)
  2188. Changes in 2.0:
  2189. * Split out `dash-functional.el' (Matus Goljer)
  2190. * Add `-andfn', `-orfn', `-not', `-cut', `-const', `-flip' and
  2191. `-on'. (Matus Goljer)
  2192. * Fix `-min', `-max', `-min-by' and `-max-by' (Matus Goljer)
  2193. Changes in 1.8:
  2194. * Add `-first-item' and `-last-item' (Wilfred Hughes)
  2195. Changes in 1.7:
  2196. * Add `-rotate' (Matus Goljer)
  2197. Changes in 1.6:
  2198. * Add `-min', `-max', `-min-by' and `-max-by' (Johan Andersson)
  2199. Changes in 1.5:
  2200. * Add `-sum' and `-product' (Johan Andersson)
  2201. Changes in 1.4:
  2202. * Add `-sort'
  2203. * Add `-reduce-r' (Matus Goljer)
  2204. * Add `-reduce-r-from' (Matus Goljer)
  2205. Changes in 1.3:
  2206. * Add `-partition-in-steps'
  2207. * Add `-partition-all-in-steps'
  2208. Changes in 1.2:
  2209. * Add `-last' (Matus Goljer)
  2210. * Add `-insert-at' (Emanuel Evans)
  2211. * Add `-when-let' and `-if-let' (Emanuel Evans)
  2212. * Add `-when-let*' and `-if-let*' (Emanuel Evans)
  2213. * Some bugfixes
  2214. 
  2215. File: dash.info, Node: Contributors, Prev: Changes, Up: Development
  2216. 3.3 Contributors
  2217. ================
  2218. * Matus Goljer (https://github.com/Fuco1) contributed lots of
  2219. features and functions.
  2220. * Takafumi Arakaki (https://github.com/tkf) contributed `-group-by'.
  2221. * tali713 (https://github.com/tali713) is the author of `-applify'.
  2222. * Víctor M. Valenzuela (https://github.com/vemv) contributed
  2223. `-repeat'.
  2224. * Nic Ferrier (https://github.com/nicferrier) contributed `-cons*'.
  2225. * Wilfred Hughes (https://github.com/Wilfred) contributed `-slice',
  2226. `-first-item' and `-last-item'.
  2227. * Emanuel Evans (https://github.com/shosti) contributed `-if-let',
  2228. `-when-let' and `-insert-at'.
  2229. * Johan Andersson (https://github.com/rejeep) contributed `-sum',
  2230. `-product' and `-same-items?'
  2231. * Christina Whyte (https://github.com/kurisuwhyte) contributed
  2232. `-compose'
  2233. * Steve Lamb (https://github.com/steventlamb) contributed `-cycle',
  2234. `-pad', `-annotate', `-zip-fill' and an n-ary version of `-zip'.
  2235. * Fredrik Bergroth (https://github.com/fbergroth) made the `-if-let'
  2236. family use `-let' destructuring and improved script for generating
  2237. documentation.
  2238. * Mark Oteiza (https://github.com/holomorph) contributed the script
  2239. to create an info manual.
  2240. * Vasilij Schneidermann (https://github.com/wasamasa) contributed
  2241. `-some'.
  2242. * William West (https://github.com/occidens) made `-fixfn' more
  2243. robust at handling floats.
  2244. Thanks!
  2245. 
  2246. File: dash.info, Node: Index, Prev: Development, Up: Top
  2247. Index
  2248. *****
  2249. [index]
  2250. * Menu:
  2251. * !cdr: Destructive operations.
  2252. (line 15)
  2253. * !cons: Destructive operations.
  2254. (line 7)
  2255. * -->: Threading macros. (line 33)
  2256. * --doto: Side-effects. (line 82)
  2257. * ->: Threading macros. (line 7)
  2258. * ->>: Threading macros. (line 20)
  2259. * -all?: Predicates. (line 19)
  2260. * -andfn: Function combinators.
  2261. (line 140)
  2262. * -annotate: Maps. (line 80)
  2263. * -any?: Predicates. (line 7)
  2264. * -applify: Function combinators.
  2265. (line 57)
  2266. * -as->: Threading macros. (line 47)
  2267. * -butlast: Other list operations.
  2268. (line 341)
  2269. * -clone: Tree operations. (line 123)
  2270. * -common-prefix: Reductions. (line 225)
  2271. * -common-suffix: Reductions. (line 235)
  2272. * -compose: Function combinators.
  2273. (line 43)
  2274. * -concat: List to list. (line 23)
  2275. * -cons*: Other list operations.
  2276. (line 31)
  2277. * -const: Function combinators.
  2278. (line 94)
  2279. * -contains?: Predicates. (line 58)
  2280. * -copy: Maps. (line 135)
  2281. * -count: Reductions. (line 153)
  2282. * -cut: Function combinators.
  2283. (line 106)
  2284. * -cycle: Other list operations.
  2285. (line 169)
  2286. * -difference: Set operations. (line 21)
  2287. * -distinct: Set operations. (line 63)
  2288. * -dotimes: Side-effects. (line 62)
  2289. * -doto: Side-effects. (line 71)
  2290. * -drop: Sublist selection. (line 125)
  2291. * -drop-last: Sublist selection. (line 137)
  2292. * -drop-while: Sublist selection. (line 158)
  2293. * -each: Side-effects. (line 9)
  2294. * -each-indexed: Side-effects. (line 29)
  2295. * -each-r: Side-effects. (line 42)
  2296. * -each-r-while: Side-effects. (line 53)
  2297. * -each-while: Side-effects. (line 20)
  2298. * -elem-index: Indexing. (line 10)
  2299. * -elem-indices: Indexing. (line 22)
  2300. * -fifth-item: Other list operations.
  2301. (line 321)
  2302. * -filter: Sublist selection. (line 9)
  2303. * -find-index: Indexing. (line 33)
  2304. * -find-indices: Indexing. (line 61)
  2305. * -find-last-index: Indexing. (line 47)
  2306. * -first: Other list operations.
  2307. (line 235)
  2308. * -first-item: Other list operations.
  2309. (line 272)
  2310. * -fix: Other list operations.
  2311. (line 377)
  2312. * -fixfn: Function combinators.
  2313. (line 177)
  2314. * -flatten: List to list. (line 34)
  2315. * -flatten-n: List to list. (line 56)
  2316. * -flip: Function combinators.
  2317. (line 82)
  2318. * -fourth-item: Other list operations.
  2319. (line 311)
  2320. * -grade-down: Indexing. (line 82)
  2321. * -grade-up: Indexing. (line 72)
  2322. * -group-by: Partitioning. (line 188)
  2323. * -if-let: Binding. (line 38)
  2324. * -if-let*: Binding. (line 51)
  2325. * -inits: Reductions. (line 205)
  2326. * -insert-at: List to list. (line 110)
  2327. * -interleave: Other list operations.
  2328. (line 69)
  2329. * -interpose: Other list operations.
  2330. (line 59)
  2331. * -intersection: Set operations. (line 33)
  2332. * -is-infix?: Predicates. (line 111)
  2333. * -is-prefix?: Predicates. (line 87)
  2334. * -is-suffix?: Predicates. (line 99)
  2335. * -iterate: Unfolding. (line 10)
  2336. * -iteratefn: Function combinators.
  2337. (line 154)
  2338. * -juxt: Function combinators.
  2339. (line 32)
  2340. * -keep: List to list. (line 9)
  2341. * -lambda: Binding. (line 259)
  2342. * -last: Other list operations.
  2343. (line 262)
  2344. * -last-item: Other list operations.
  2345. (line 331)
  2346. * -let: Binding. (line 67)
  2347. * -let*: Binding. (line 239)
  2348. * -list: Other list operations.
  2349. (line 364)
  2350. * -map: Maps. (line 11)
  2351. * -map-first: Maps. (line 38)
  2352. * -map-indexed: Maps. (line 66)
  2353. * -map-last: Maps. (line 52)
  2354. * -map-when: Maps. (line 22)
  2355. * -mapcat: Maps. (line 124)
  2356. * -max: Reductions. (line 269)
  2357. * -max-by: Reductions. (line 279)
  2358. * -min: Reductions. (line 245)
  2359. * -min-by: Reductions. (line 255)
  2360. * -non-nil: Sublist selection. (line 80)
  2361. * -none?: Predicates. (line 31)
  2362. * -not: Function combinators.
  2363. (line 119)
  2364. * -on: Function combinators.
  2365. (line 68)
  2366. * -only-some?: Predicates. (line 43)
  2367. * -orfn: Function combinators.
  2368. (line 128)
  2369. * -pad: Other list operations.
  2370. (line 180)
  2371. * -partial: Function combinators.
  2372. (line 10)
  2373. * -partition: Partitioning. (line 75)
  2374. * -partition-after-item: Partitioning. (line 178)
  2375. * -partition-after-pred: Partitioning. (line 146)
  2376. * -partition-all: Partitioning. (line 87)
  2377. * -partition-all-in-steps: Partitioning. (line 110)
  2378. * -partition-before-item: Partitioning. (line 168)
  2379. * -partition-before-pred: Partitioning. (line 157)
  2380. * -partition-by: Partitioning. (line 122)
  2381. * -partition-by-header: Partitioning. (line 133)
  2382. * -partition-in-steps: Partitioning. (line 98)
  2383. * -permutations: Set operations. (line 53)
  2384. * -powerset: Set operations. (line 45)
  2385. * -prodfn: Function combinators.
  2386. (line 212)
  2387. * -product: Reductions. (line 183)
  2388. * -reduce: Reductions. (line 47)
  2389. * -reduce-from: Reductions. (line 9)
  2390. * -reduce-r: Reductions. (line 67)
  2391. * -reduce-r-from: Reductions. (line 28)
  2392. * -reductions: Reductions. (line 121)
  2393. * -reductions-from: Reductions. (line 89)
  2394. * -reductions-r: Reductions. (line 137)
  2395. * -reductions-r-from: Reductions. (line 105)
  2396. * -remove: Sublist selection. (line 24)
  2397. * -remove-at: List to list. (line 146)
  2398. * -remove-at-indices: List to list. (line 159)
  2399. * -remove-first: Sublist selection. (line 38)
  2400. * -remove-item: Sublist selection. (line 68)
  2401. * -remove-last: Sublist selection. (line 53)
  2402. * -repeat: Other list operations.
  2403. (line 20)
  2404. * -replace: List to list. (line 68)
  2405. * -replace-at: List to list. (line 121)
  2406. * -replace-first: List to list. (line 82)
  2407. * -replace-last: List to list. (line 96)
  2408. * -rotate: Other list operations.
  2409. (line 9)
  2410. * -rpartial: Function combinators.
  2411. (line 21)
  2412. * -running-product: Reductions. (line 193)
  2413. * -running-sum: Reductions. (line 171)
  2414. * -same-items?: Predicates. (line 73)
  2415. * -second-item: Other list operations.
  2416. (line 287)
  2417. * -select-by-indices: Sublist selection. (line 169)
  2418. * -select-column: Sublist selection. (line 199)
  2419. * -select-columns: Sublist selection. (line 180)
  2420. * -separate: Partitioning. (line 64)
  2421. * -setq: Binding. (line 281)
  2422. * -slice: Sublist selection. (line 86)
  2423. * -snoc: Other list operations.
  2424. (line 45)
  2425. * -some: Other list operations.
  2426. (line 249)
  2427. * -some-->: Threading macros. (line 84)
  2428. * -some->: Threading macros. (line 60)
  2429. * -some->>: Threading macros. (line 72)
  2430. * -sort: Other list operations.
  2431. (line 351)
  2432. * -splice: Maps. (line 91)
  2433. * -splice-list: Maps. (line 111)
  2434. * -split-at: Partitioning. (line 9)
  2435. * -split-on: Partitioning. (line 29)
  2436. * -split-when: Partitioning. (line 47)
  2437. * -split-with: Partitioning. (line 18)
  2438. * -sum: Reductions. (line 161)
  2439. * -table: Other list operations.
  2440. (line 191)
  2441. * -table-flat: Other list operations.
  2442. (line 210)
  2443. * -tails: Reductions. (line 215)
  2444. * -take: Sublist selection. (line 102)
  2445. * -take-last: Sublist selection. (line 113)
  2446. * -take-while: Sublist selection. (line 147)
  2447. * -third-item: Other list operations.
  2448. (line 299)
  2449. * -tree-map: Tree operations. (line 29)
  2450. * -tree-map-nodes: Tree operations. (line 40)
  2451. * -tree-mapreduce: Tree operations. (line 85)
  2452. * -tree-mapreduce-from: Tree operations. (line 104)
  2453. * -tree-reduce: Tree operations. (line 53)
  2454. * -tree-reduce-from: Tree operations. (line 70)
  2455. * -tree-seq: Tree operations. (line 9)
  2456. * -unfold: Unfolding. (line 26)
  2457. * -union: Set operations. (line 9)
  2458. * -unzip: Other list operations.
  2459. (line 147)
  2460. * -update-at: List to list. (line 133)
  2461. * -when-let: Binding. (line 10)
  2462. * -when-let*: Binding. (line 24)
  2463. * -zip: Other list operations.
  2464. (line 96)
  2465. * -zip-fill: Other list operations.
  2466. (line 139)
  2467. * -zip-lists: Other list operations.
  2468. (line 120)
  2469. * -zip-with: Other list operations.
  2470. (line 80)
  2471. 
  2472. Tag Table:
  2473. Node: Top1042
  2474. Node: Installation2518
  2475. Node: Using in a package3037
  2476. Node: Syntax highlighting of dash functions3401
  2477. Node: Functions3784
  2478. Node: Maps4985
  2479. Ref: -map5280
  2480. Ref: -map-when5618
  2481. Ref: -map-first6185
  2482. Ref: -map-last6652
  2483. Ref: -map-indexed7114
  2484. Ref: -annotate7580
  2485. Ref: -splice8067
  2486. Ref: -splice-list8833
  2487. Ref: -mapcat9284
  2488. Ref: -copy9657
  2489. Node: Sublist selection9859
  2490. Ref: -filter10052
  2491. Ref: -remove10489
  2492. Ref: -remove-first10884
  2493. Ref: -remove-last11396
  2494. Ref: -remove-item11902
  2495. Ref: -non-nil12290
  2496. Ref: -slice12448
  2497. Ref: -take12977
  2498. Ref: -take-last13279
  2499. Ref: -drop13595
  2500. Ref: -drop-last13862
  2501. Ref: -take-while14116
  2502. Ref: -drop-while14463
  2503. Ref: -select-by-indices14816
  2504. Ref: -select-columns15323
  2505. Ref: -select-column16017
  2506. Node: List to list16471
  2507. Ref: -keep16663
  2508. Ref: -concat17159
  2509. Ref: -flatten17453
  2510. Ref: -flatten-n18195
  2511. Ref: -replace18575
  2512. Ref: -replace-first19027
  2513. Ref: -replace-last19513
  2514. Ref: -insert-at19992
  2515. Ref: -replace-at20309
  2516. Ref: -update-at20692
  2517. Ref: -remove-at21172
  2518. Ref: -remove-at-indices21649
  2519. Node: Reductions22216
  2520. Ref: -reduce-from22385
  2521. Ref: -reduce-r-from23131
  2522. Ref: -reduce23882
  2523. Ref: -reduce-r24595
  2524. Ref: -reductions-from25449
  2525. Ref: -reductions-r-from26145
  2526. Ref: -reductions26851
  2527. Ref: -reductions-r27457
  2528. Ref: -count28073
  2529. Ref: -sum28295
  2530. Ref: -running-sum28481
  2531. Ref: -product28771
  2532. Ref: -running-product28977
  2533. Ref: -inits29287
  2534. Ref: -tails29532
  2535. Ref: -common-prefix29776
  2536. Ref: -common-suffix30070
  2537. Ref: -min30364
  2538. Ref: -min-by30587
  2539. Ref: -max31103
  2540. Ref: -max-by31325
  2541. Node: Unfolding31846
  2542. Ref: -iterate32085
  2543. Ref: -unfold32527
  2544. Node: Predicates33318
  2545. Ref: -any?33442
  2546. Ref: -all?33747
  2547. Ref: -none?34062
  2548. Ref: -only-some?34357
  2549. Ref: -contains?34827
  2550. Ref: -same-items?35199
  2551. Ref: -is-prefix?35577
  2552. Ref: -is-suffix?35893
  2553. Ref: -is-infix?36209
  2554. Node: Partitioning36556
  2555. Ref: -split-at36744
  2556. Ref: -split-with37027
  2557. Ref: -split-on37427
  2558. Ref: -split-when38088
  2559. Ref: -separate38717
  2560. Ref: -partition39156
  2561. Ref: -partition-all39605
  2562. Ref: -partition-in-steps40030
  2563. Ref: -partition-all-in-steps40524
  2564. Ref: -partition-by41006
  2565. Ref: -partition-by-header41385
  2566. Ref: -partition-after-pred41985
  2567. Ref: -partition-before-pred42326
  2568. Ref: -partition-before-item42674
  2569. Ref: -partition-after-item42982
  2570. Ref: -group-by43285
  2571. Node: Indexing43715
  2572. Ref: -elem-index43917
  2573. Ref: -elem-indices44309
  2574. Ref: -find-index44689
  2575. Ref: -find-last-index45171
  2576. Ref: -find-indices45668
  2577. Ref: -grade-up46073
  2578. Ref: -grade-down46474
  2579. Node: Set operations46882
  2580. Ref: -union47065
  2581. Ref: -difference47494
  2582. Ref: -intersection47898
  2583. Ref: -powerset48322
  2584. Ref: -permutations48533
  2585. Ref: -distinct48830
  2586. Node: Other list operations49191
  2587. Ref: -rotate49416
  2588. Ref: -repeat49783
  2589. Ref: -cons*50043
  2590. Ref: -snoc50427
  2591. Ref: -interpose50833
  2592. Ref: -interleave51128
  2593. Ref: -zip-with51494
  2594. Ref: -zip52196
  2595. Ref: -zip-lists53011
  2596. Ref: -zip-fill53700
  2597. Ref: -unzip54021
  2598. Ref: -cycle54755
  2599. Ref: -pad55125
  2600. Ref: -table55445
  2601. Ref: -table-flat56228
  2602. Ref: -first57224
  2603. Ref: -some57585
  2604. Ref: -last57887
  2605. Ref: -first-item58218
  2606. Ref: -second-item58623
  2607. Ref: -third-item58897
  2608. Ref: -fourth-item59169
  2609. Ref: -fifth-item59429
  2610. Ref: -last-item59685
  2611. Ref: -butlast59974
  2612. Ref: -sort60218
  2613. Ref: -list60703
  2614. Ref: -fix61031
  2615. Node: Tree operations61565
  2616. Ref: -tree-seq61761
  2617. Ref: -tree-map62616
  2618. Ref: -tree-map-nodes63056
  2619. Ref: -tree-reduce63903
  2620. Ref: -tree-reduce-from64778
  2621. Ref: -tree-mapreduce65377
  2622. Ref: -tree-mapreduce-from66221
  2623. Ref: -clone67491
  2624. Node: Threading macros67818
  2625. Ref: ->67963
  2626. Ref: ->>68450
  2627. Ref: -->68951
  2628. Ref: -as->69495
  2629. Ref: -some->69947
  2630. Ref: -some->>70314
  2631. Ref: -some-->70743
  2632. Node: Binding71206
  2633. Ref: -when-let71410
  2634. Ref: -when-let*71888
  2635. Ref: -if-let72409
  2636. Ref: -if-let*72798
  2637. Ref: -let73407
  2638. Ref: -let*79831
  2639. Ref: -lambda80765
  2640. Ref: -setq81554
  2641. Node: Side-effects82399
  2642. Ref: -each82593
  2643. Ref: -each-while82996
  2644. Ref: -each-indexed83354
  2645. Ref: -each-r83858
  2646. Ref: -each-r-while84289
  2647. Ref: -dotimes84662
  2648. Ref: -doto84963
  2649. Ref: --doto85387
  2650. Node: Destructive operations85652
  2651. Ref: !cons85825
  2652. Ref: !cdr86029
  2653. Node: Function combinators86222
  2654. Ref: -partial86491
  2655. Ref: -rpartial86884
  2656. Ref: -juxt87284
  2657. Ref: -compose87713
  2658. Ref: -applify88267
  2659. Ref: -on88695
  2660. Ref: -flip89218
  2661. Ref: -const89527
  2662. Ref: -cut89863
  2663. Ref: -not90346
  2664. Ref: -orfn90654
  2665. Ref: -andfn91086
  2666. Ref: -iteratefn91578
  2667. Ref: -fixfn92274
  2668. Ref: -prodfn93818
  2669. Node: Development94871
  2670. Node: Contribute95220
  2671. Node: Changes95941
  2672. Node: Contributors98555
  2673. Node: Index100067
  2674. 
  2675. End Tag Table