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.

3410 lines
119 KiB

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