[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/dash d0c6fc0 371/426: Merge pull request #104 from fber
From: |
Phillip Lord |
Subject: |
[elpa] externals/dash d0c6fc0 371/426: Merge pull request #104 from fbergroth/linkify-docs |
Date: |
Tue, 04 Aug 2015 19:38:59 +0000 |
branch: externals/dash
commit d0c6fc06f8fb150d8e97e52e10c06137497a1a99
Merge: 75d29a2 c7b4cff
Author: Matus Goljer <address@hidden>
Commit: Matus Goljer <address@hidden>
Merge pull request #104 from fbergroth/linkify-docs
Linkify docs
---
README.md | 328 +++++++++++++++++++++++-----------------------
dev/examples-to-docs.el | 23 ++-
readme-template.md | 4 +-
3 files changed, 181 insertions(+), 174 deletions(-)
diff --git a/README.md b/README.md
index 35bf929..041dfe3 100644
--- a/README.md
+++ b/README.md
@@ -265,7 +265,7 @@ While `-map` takes a function to map over the list, you can
also use
the anaphoric form with double dashes - which will then be executed
with `it` exposed as the list item. Here's an example:
-```cl
+```el
(-map (lambda (n) (* n n)) '(1 2 3 4)) ;; normal version
(--map (* it it) '(1 2 3 4)) ;; anaphoric version
@@ -273,7 +273,7 @@ with `it` exposed as the list item. Here's an example:
of course the original can also be written like
-```cl
+```el
(defun square (n) (* n n))
(-map 'square '(1 2 3 4))
@@ -294,7 +294,7 @@ new list.
Return a new list consisting of the result of applying `fn` to the items in
`list`.
-```cl
+```el
(-map (lambda (num) (* num num)) '(1 2 3 4)) ;; => '(1 4 9 16)
(-map 'square '(1 2 3 4)) ;; => '(1 4 9 16)
(--map (* it it) '(1 2 3 4)) ;; => '(1 4 9 16)
@@ -308,9 +308,9 @@ through the `rep` function.
Alias: `-replace-where`
-See also: `-update-at`
+See also: [`-update-at`](#-update-at-n-func-list)
-```cl
+```el
(-map-when 'even? 'square '(1 2 3 4)) ;; => '(1 4 3 16)
(--map-when (> it 2) (* it it) '(1 2 3 4)) ;; => '(1 2 9 16)
(--map-when (= it 2) 17 '(1 2 3 4)) ;; => '(1 17 3 4)
@@ -322,7 +322,7 @@ Return a new list consisting of the result of (`fn` index
item) for each item in
In the anaphoric form `--map-indexed`, the index is exposed as `it-index`.
-```cl
+```el
(-map-indexed (lambda (index item) (- item index)) '(1 2 3 4)) ;; => '(1 1 1 1)
(--map-indexed (- it it-index) '(1 2 3 4)) ;; => '(1 1 1 1)
```
@@ -332,7 +332,7 @@ In the anaphoric form `--map-indexed`, the index is exposed
as `it-index`.
Return a list of cons cells where each cell is `fn` applied to each
element of `list` paired with the unmodified element of `list`.
-```cl
+```el
(-annotate '1+ '(1 2 3)) ;; => '((2 . 1) (3 . 2) (4 . 3))
(-annotate 'length '(("h" "e" "l" "l" "o") ("hello" "world"))) ;; => '((5 "h"
"e" "l" "l" "o") (2 "hello" "world"))
(--annotate (< 1 it) '(0 1 2 3)) ;; => '((nil . 0) (nil . 1) (t . 2) (t . 3))
@@ -348,9 +348,9 @@ This function can be used as replacement for `,@` in case
you
need to splice several lists at marked positions (for example
with keywords).
-See also: `-splice-list`, `-insert-at`
+See also: [`-splice-list`](#-splice-list-pred-new-list-list),
[`-insert-at`](#-insert-at-n-x-list)
-```cl
+```el
(-splice 'even? (lambda (x) (list x x)) '(1 2 3 4)) ;; => '(1 2 2 3 4 4)
(--splice 't (list it it) '(1 2 3 4)) ;; => '(1 1 2 2 3 3 4 4)
(--splice (equal it :magic) '((list of) (magical) (code)) '((foo) (bar) :magic
(baz))) ;; => '((foo) (bar) (list of) (magical) (code) (baz))
@@ -360,9 +360,9 @@ See also: `-splice-list`, `-insert-at`
Splice `new-list` in place of elements matching `pred` in `list`.
-See also: `-splice`, `-insert-at`
+See also: [`-splice`](#-splice-pred-fun-list),
[`-insert-at`](#-insert-at-n-x-list)
-```cl
+```el
(-splice-list 'keywordp '(a b c) '(1 :foo 2)) ;; => '(1 a b c 2)
(-splice-list 'keywordp nil '(1 :foo 2)) ;; => '(1 2)
```
@@ -372,7 +372,7 @@ See also: `-splice`, `-insert-at`
Return the concatenation of the result of mapping `fn` over `list`.
Thus function `fn` should return a list.
-```cl
+```el
(-mapcat 'list '(1 2 3)) ;; => '(1 2 3)
(-mapcat (lambda (item) (list 0 item)) '(1 2 3)) ;; => '(0 1 0 2 0 3)
(--mapcat (list 0 it) '(1 2 3)) ;; => '(0 1 0 2 0 3)
@@ -382,7 +382,7 @@ Thus function `fn` should return a list.
Create a shallow copy of `list`.
-```cl
+```el
(-copy '(1 2 3)) ;; => '(1 2 3)
(let ((a '(1 2 3))) (eq a (-copy a))) ;; => nil
```
@@ -399,7 +399,7 @@ Return a new list of the items in `list` for which `pred`
returns a non-nil valu
Alias: `-select`
-```cl
+```el
(-filter (lambda (num) (= 0 (% num 2))) '(1 2 3 4)) ;; => '(2 4)
(-filter 'even? '(1 2 3 4)) ;; => '(2 4)
(--filter (= 0 (% it 2)) '(1 2 3 4)) ;; => '(2 4)
@@ -411,7 +411,7 @@ Return a new list of the items in `list` for which `pred`
returns nil.
Alias: `-reject`
-```cl
+```el
(-remove (lambda (num) (= 0 (% num 2))) '(1 2 3 4)) ;; => '(1 3)
(-remove 'even? '(1 2 3 4)) ;; => '(1 3)
(--remove (= 0 (% it 2)) '(1 2 3 4)) ;; => '(1 3)
@@ -421,7 +421,7 @@ Alias: `-reject`
Return all non-nil elements of `list`.
-```cl
+```el
(-non-nil '(1 nil 2 nil nil 3 4 nil 5 nil)) ;; => '(1 2 3 4 5)
```
@@ -435,7 +435,7 @@ modulo the length of the list.
If `step` is a number, only each STEPth item in the resulting
section is returned. Defaults to 1.
-```cl
+```el
(-slice '(1 2 3 4 5) 1) ;; => '(2 3 4 5)
(-slice '(1 2 3 4 5) 0 3) ;; => '(1 2 3)
(-slice '(1 2 3 4 5 6 7 8 9) 1 -1 2) ;; => '(2 4 6 8)
@@ -445,7 +445,7 @@ section is returned. Defaults to 1.
Return a new list of the first `n` items in `list`, or all items if there are
fewer than `n`.
-```cl
+```el
(-take 3 '(1 2 3 4 5)) ;; => '(1 2 3)
(-take 17 '(1 2 3 4 5)) ;; => '(1 2 3 4 5)
```
@@ -454,7 +454,7 @@ Return a new list of the first `n` items in `list`, or all
items if there are fe
Return the tail of `list` without the first `n` items.
-```cl
+```el
(-drop 3 '(1 2 3 4 5)) ;; => '(4 5)
(-drop 17 '(1 2 3 4 5)) ;; => '()
```
@@ -463,7 +463,7 @@ Return the tail of `list` without the first `n` items.
Return a new list of successive items from `list` while (`pred` item) returns
a non-nil value.
-```cl
+```el
(-take-while 'even? '(1 2 3 4)) ;; => '()
(-take-while 'even? '(2 4 5 6)) ;; => '(2 4)
(--take-while (< it 4) '(1 2 3 4 3 2 1)) ;; => '(1 2 3)
@@ -473,7 +473,7 @@ Return a new list of successive items from `list` while
(`pred` item) returns a
Return the tail of `list` starting from the first item for which (`pred` item)
returns nil.
-```cl
+```el
(-drop-while 'even? '(1 2 3 4)) ;; => '(1 2 3 4)
(-drop-while 'even? '(2 4 5 6)) ;; => '(5 6)
(--drop-while (< it 4) '(1 2 3 4 3 2 1)) ;; => '(4 3 2 1)
@@ -484,7 +484,7 @@ Return the tail of `list` starting from the first item for
which (`pred` item) r
Return a list whose elements are elements from `list` selected
as `(nth i list)` for all i from `indices`.
-```cl
+```el
(-select-by-indices '(4 10 2 3 6) '("v" "e" "l" "o" "c" "i" "r" "a" "p" "t"
"o" "r")) ;; => '("c" "o" "l" "o" "r")
(-select-by-indices '(2 1 0) '("a" "b" "c")) ;; => '("c" "b" "a")
(-select-by-indices '(0 1 2 0 1 3 3 1) '("f" "a" "r" "l")) ;; => '("f" "a" "r"
"f" "a" "l" "l" "a")
@@ -500,7 +500,7 @@ Bag of various functions which modify input list.
Return a new list of the non-nil results of applying `fn` to the items in
`list`.
-```cl
+```el
(-keep 'cdr '((1 2 3) (4 5) (6))) ;; => '((2 3) (5))
(-keep (lambda (num) (when (> num 3) (* 10 num))) '(1 2 3 4 5 6)) ;; => '(40
50 60)
(--keep (when (> it 3) (* 10 it)) '(1 2 3 4 5 6)) ;; => '(40 50 60)
@@ -510,7 +510,7 @@ Return a new list of the non-nil results of applying `fn`
to the items in `list`
Return a new list with the concatenation of the elements in the supplied
`lists`.
-```cl
+```el
(-concat '(1)) ;; => '(1)
(-concat '(1) '(2)) ;; => '(1 2)
(-concat '(1) '(2 3) '(4)) ;; => '(1 2 3 4)
@@ -520,9 +520,9 @@ Return a new list with the concatenation of the elements in
the supplied `lists`
Take a nested list `l` and return its contents as a single, flat list.
-See also: `-flatten-n`
+See also: [`-flatten-n`](#-flatten-n-num-list)
-```cl
+```el
(-flatten '((1))) ;; => '(1)
(-flatten '((1 (2 3) (((4 (5))))))) ;; => '(1 2 3 4 5)
(-flatten '(1 2 (3 . 4))) ;; => '(1 2 (3 . 4))
@@ -532,9 +532,9 @@ See also: `-flatten-n`
Flatten `num` levels of a nested `list`.
-See also: `-flatten`
+See also: [`-flatten`](#-flatten-l)
-```cl
+```el
(-flatten-n 1 '((1 2) ((3 4) ((5 6))))) ;; => '(1 2 (3 4) ((5 6)))
(-flatten-n 2 '((1 2) ((3 4) ((5 6))))) ;; => '(1 2 3 4 (5 6))
(-flatten-n 3 '((1 2) ((3 4) ((5 6))))) ;; => '(1 2 3 4 5 6)
@@ -546,9 +546,9 @@ Replace all `old` items in `list` with `new`.
Elements are compared using `equal`.
-See also: `-replace-at`
+See also: [`-replace-at`](#-replace-at-n-x-list)
-```cl
+```el
(-replace 1 "1" '(1 2 3 4 3 2 1)) ;; => '("1" 2 3 4 3 2 "1")
(-replace "foo" "bar" '("a" "nice" "foo" "sentence" "about" "foo")) ;; =>
'("a" "nice" "bar" "sentence" "about" "bar")
(-replace 1 2 nil) ;; => nil
@@ -558,9 +558,9 @@ See also: `-replace-at`
Return a list with `x` inserted into `list` at position `n`.
-See also: `-splice`, `-splice-list`
+See also: [`-splice`](#-splice-pred-fun-list),
[`-splice-list`](#-splice-list-pred-new-list-list)
-```cl
+```el
(-insert-at 1 'x '(a b c)) ;; => '(a x b c)
(-insert-at 12 'x '(a b c)) ;; => '(a b c x)
```
@@ -569,9 +569,9 @@ See also: `-splice`, `-splice-list`
Return a list with element at Nth position in `list` replaced with `x`.
-See also: `-replace`
+See also: [`-replace`](#-replace-old-new-list)
-```cl
+```el
(-replace-at 0 9 '(0 1 2 3 4 5)) ;; => '(9 1 2 3 4 5)
(-replace-at 1 9 '(0 1 2 3 4 5)) ;; => '(0 9 2 3 4 5)
(-replace-at 4 9 '(0 1 2 3 4 5)) ;; => '(0 1 2 3 9 5)
@@ -581,9 +581,9 @@ See also: `-replace`
Return a list with element at Nth position in `list` replaced with `(func (nth
n list))`.
-See also: `-map-when`
+See also: [`-map-when`](#-map-when-pred-rep-list)
-```cl
+```el
(-update-at 0 (lambda (x) (+ x 9)) '(0 1 2 3 4 5)) ;; => '(9 1 2 3 4 5)
(-update-at 1 (lambda (x) (+ x 8)) '(0 1 2 3 4 5)) ;; => '(0 9 2 3 4 5)
(--update-at 2 (length it) '("foo" "bar" "baz" "quux")) ;; => '("foo" "bar" 3
"quux")
@@ -593,9 +593,9 @@ See also: `-map-when`
Return a list with element at Nth position in `list` removed.
-See also: `-remove-at-indices`, `-remove`
+See also: [`-remove-at-indices`](#-remove-at-indices-indices-list),
[`-remove`](#-remove-pred-list)
-```cl
+```el
(-remove-at 0 '("0" "1" "2" "3" "4" "5")) ;; => '("1" "2" "3" "4" "5")
(-remove-at 1 '("0" "1" "2" "3" "4" "5")) ;; => '("0" "2" "3" "4" "5")
(-remove-at 2 '("0" "1" "2" "3" "4" "5")) ;; => '("0" "1" "3" "4" "5")
@@ -607,9 +607,9 @@ Return a list whose elements are elements from `list`
without
elements selected as `(nth i list)` for all i
from `indices`.
-See also: `-remove-at`, `-remove`
+See also: [`-remove-at`](#-remove-at-n-list), [`-remove`](#-remove-pred-list)
-```cl
+```el
(-remove-at-indices '(0) '("0" "1" "2" "3" "4" "5")) ;; => '("1" "2" "3" "4"
"5")
(-remove-at-indices '(0 2 4) '("0" "1" "2" "3" "4" "5")) ;; => '("1" "3" "5")
(-remove-at-indices '(0 5) '("0" "1" "2" "3" "4" "5")) ;; => '("1" "2" "3" "4")
@@ -631,7 +631,7 @@ item, etc. If `list` contains no items, return
`initial-value` and
In the anaphoric form `--reduce-from`, the accumulated value is
exposed as `acc`.
-```cl
+```el
(-reduce-from '- 10 '(1 2 3)) ;; => 4
(-reduce-from (lambda (memo item) (concat "(" memo " - " (int-to-string item)
")")) "10" '(1 2 3)) ;; => "(((10 - 1) - 2) - 3)"
(--reduce-from (concat acc " " it) "START" '("a" "b" "c")) ;; => "START a b c"
@@ -643,10 +643,10 @@ Replace conses with `fn`, nil with `initial-value` and
evaluate
the resulting expression. If `list` is empty, `initial-value` is
returned and `fn` is not called.
-Note: this function works the same as `-reduce-from` but the
+Note: this function works the same as
[`-reduce-from`](#-reduce-from-fn-initial-value-list) but the
operation associates from right instead of from left.
-```cl
+```el
(-reduce-r-from '- 10 '(1 2 3)) ;; => -8
(-reduce-r-from (lambda (item memo) (concat "(" (int-to-string item) " - "
memo ")")) "10" '(1 2 3)) ;; => "(1 - (2 - (3 - 10)))"
(--reduce-r-from (concat it " " acc) "END" '("a" "b" "c")) ;; => "a b c END"
@@ -663,7 +663,7 @@ reduce return the result of calling `fn` with no arguments.
If
In the anaphoric form `--reduce`, the accumulated value is
exposed as `acc`.
-```cl
+```el
(-reduce '- '(1 2 3 4)) ;; => -8
(-reduce (lambda (memo item) (format "%s-%s" memo item)) '(1 2 3)) ;; =>
"1-2-3"
(--reduce (format "%s-%s" acc it) '(1 2 3)) ;; => "1-2-3"
@@ -680,10 +680,10 @@ returned and `fn` is not called.
The first argument of `fn` is the new item, the second is the
accumulated value.
-Note: this function works the same as `-reduce` but the operation
+Note: this function works the same as [`-reduce`](#-reduce-fn-list) but the
operation
associates from right instead of from left.
-```cl
+```el
(-reduce-r '- '(1 2 3 4)) ;; => -2
(-reduce-r (lambda (item memo) (format "%s-%s" memo item)) '(1 2 3)) ;; =>
"3-2-1"
(--reduce-r (format "%s-%s" acc it) '(1 2 3)) ;; => "3-2-1"
@@ -693,7 +693,7 @@ associates from right instead of from left.
Counts the number of items in `list` where (`pred` item) is non-nil.
-```cl
+```el
(-count 'even? '(1 2 3 4 5)) ;; => 2
(--count (< it 4) '(1 2 3 4)) ;; => 3
```
@@ -702,7 +702,7 @@ Counts the number of items in `list` where (`pred` item) is
non-nil.
Return the sum of `list`.
-```cl
+```el
(-sum '()) ;; => 0
(-sum '(1)) ;; => 1
(-sum '(1 2 3 4)) ;; => 10
@@ -712,7 +712,7 @@ Return the sum of `list`.
Return the product of `list`.
-```cl
+```el
(-product '()) ;; => 1
(-product '(1)) ;; => 1
(-product '(1 2 3 4)) ;; => 24
@@ -722,7 +722,7 @@ Return the product of `list`.
Return the smallest value from `list` of numbers or markers.
-```cl
+```el
(-min '(0)) ;; => 0
(-min '(3 2 1)) ;; => 1
(-min '(1 2 3)) ;; => 1
@@ -733,10 +733,10 @@ Return the smallest value from `list` of numbers or
markers.
Take a comparison function `comparator` and a `list` and return
the least element of the list by the comparison function.
-See also combinator `-on` which can transform the values before
+See also combinator [`-on`](#-on-operator-transformer) which can transform the
values before
comparing them.
-```cl
+```el
(-min-by '> '(4 3 6 1)) ;; => 1
(--min-by (> (car it) (car other)) '((1 2 3) (2) (3 2))) ;; => '(1 2 3)
(--min-by (> (length it) (length other)) '((1 2 3) (2) (3 2))) ;; => '(2)
@@ -746,7 +746,7 @@ comparing them.
Return the largest value from `list` of numbers or markers.
-```cl
+```el
(-max '(0)) ;; => 0
(-max '(3 2 1)) ;; => 3
(-max '(1 2 3)) ;; => 3
@@ -757,10 +757,10 @@ Return the largest value from `list` of numbers or
markers.
Take a comparison function `comparator` and a `list` and return
the greatest element of the list by the comparison function.
-See also combinator `-on` which can transform the values before
+See also combinator [`-on`](#-on-operator-transformer) which can transform the
values before
comparing them.
-```cl
+```el
(-max-by '> '(4 3 6 1)) ;; => 6
(--max-by (> (car it) (car other)) '((1 2 3) (2) (3 2))) ;; => '(3 2)
(--max-by (> (length it) (length other)) '((1 2 3) (2) (3 2))) ;; => '(1 2 3)
@@ -782,7 +782,7 @@ This means a list of form:
`n` is the length of the returned list.
-```cl
+```el
(-iterate '1+ 1 10) ;; => '(1 2 3 4 5 6 7 8 9 10)
(-iterate (lambda (x) (+ x x)) 2 5) ;; => '(2 4 8 16 32)
(--iterate (* it it) 2 5) ;; => '(2 4 16 256 65536)
@@ -792,15 +792,15 @@ This means a list of form:
Build a list from `seed` using `fun`.
-This is "dual" operation to `-reduce-r`: while -reduce-r
-consumes a list to produce a single value, `-unfold` takes a
+This is "dual" operation to [`-reduce-r`](#-reduce-r-fn-list): while -reduce-r
+consumes a list to produce a single value, [`-unfold`](#-unfold-fun-seed)
takes a
seed value and builds a (potentially infinite!) list.
`fun` should return `nil` to stop the generating process, or a
cons (`a` . `b`), where `a` will be prepended to the result and `b` is
the new seed.
-```cl
+```el
(-unfold (lambda (x) (unless (= x 0) (cons x (1- x)))) 10) ;; => '(10 9 8 7 6
5 4 3 2 1)
(--unfold (when it (cons it (cdr it))) '(1 2 3 4)) ;; => '((1 2 3 4) (2 3 4)
(3 4) (4))
(--unfold (when it (cons it (butlast it))) '(1 2 3 4)) ;; => '((1 2 3 4) (1 2
3) (1 2) (1))
@@ -815,7 +815,7 @@ Return t if (`pred` x) is non-nil for any x in `list`, else
nil.
Alias: `-any-p`, `-some?`, `-some-p`
-```cl
+```el
(-any? 'even? '(1 2 3)) ;; => t
(-any? 'even? '(1 3 5)) ;; => nil
(--any? (= 0 (% it 2)) '(1 2 3)) ;; => t
@@ -827,7 +827,7 @@ Return t if (`pred` x) is non-nil for all x in `list`, else
nil.
Alias: `-all-p`, `-every?`, `-every-p`
-```cl
+```el
(-all? 'even? '(1 2 3)) ;; => nil
(-all? 'even? '(2 4 6)) ;; => t
(--all? (= 0 (% it 2)) '(2 4 6)) ;; => t
@@ -839,7 +839,7 @@ Return t if (`pred` x) is nil for all x in `list`, else nil.
Alias: `-none-p`
-```cl
+```el
(-none? 'even? '(1 2 3)) ;; => nil
(-none? 'even? '(1 3 5)) ;; => t
(--none? (= 0 (% it 2)) '(1 2 3)) ;; => nil
@@ -852,7 +852,7 @@ Return `nil` both if all items match the predicate or if
none of the items match
Alias: `-only-some-p`
-```cl
+```el
(-only-some? 'even? '(1 2 3)) ;; => t
(-only-some? 'even? '(1 3 5)) ;; => nil
(-only-some? 'even? '(2 4 6)) ;; => nil
@@ -867,7 +867,7 @@ if that's non-nil.
Alias: `-contains-p`
-```cl
+```el
(-contains? '(1 2 3) 1) ;; => t
(-contains? '(1 2 3) 2) ;; => t
(-contains? '(1 2 3) 4) ;; => nil
@@ -881,7 +881,7 @@ The order of the elements in the lists does not matter.
Alias: `-same-items-p`
-```cl
+```el
(-same-items? '(1 2 3) '(1 2 3)) ;; => t
(-same-items? '(1 2 3) '(3 2 1)) ;; => t
(-same-items? '(1 2 3) '(1 2 3 4)) ;; => nil
@@ -893,7 +893,7 @@ Return non-nil if `prefix` is prefix of `list`.
Alias: `-is-prefix-p`
-```cl
+```el
(-is-prefix? '(1 2 3) '(1 2 3 4 5)) ;; => t
(-is-prefix? '(1 2 3 4 5) '(1 2 3)) ;; => nil
(-is-prefix? '(1 3) '(1 2 3 4 5)) ;; => nil
@@ -905,7 +905,7 @@ Return non-nil if `suffix` is suffix of `list`.
Alias: `-is-suffix-p`
-```cl
+```el
(-is-suffix? '(3 4 5) '(1 2 3 4 5)) ;; => t
(-is-suffix? '(1 2 3 4 5) '(3 4 5)) ;; => nil
(-is-suffix? '(3 5) '(1 2 3 4 5)) ;; => nil
@@ -919,7 +919,7 @@ This operation runs in `o`(n^2) time
Alias: `-is-infix-p`
-```cl
+```el
(-is-infix? '(1 2 3) '(1 2 3 4 5)) ;; => t
(-is-infix? '(2 3 4) '(1 2 3 4 5)) ;; => t
(-is-infix? '(3 4 5) '(1 2 3 4 5)) ;; => t
@@ -935,7 +935,7 @@ Functions partitioning the input list into a list of lists.
Return a list of ((-take `n` `list`) (-drop `n` `list`)), in no more than one
pass through the list.
-```cl
+```el
(-split-at 3 '(1 2 3 4 5)) ;; => '((1 2 3) (4 5))
(-split-at 17 '(1 2 3 4 5)) ;; => '((1 2 3 4 5) nil)
```
@@ -944,7 +944,7 @@ Return a list of ((-take `n` `list`) (-drop `n` `list`)),
in no more than one pa
Return a list of ((-take-while `pred` `list`) (-drop-while `pred` `list`)), in
no more than one pass through the list.
-```cl
+```el
(-split-with 'even? '(1 2 3 4)) ;; => '(nil (1 2 3 4))
(-split-with 'even? '(2 4 5 6)) ;; => '((2 4) (5 6))
(--split-with (< it 4) '(1 2 3 4 3 2 1)) ;; => '((1 2 3) (4 3 2 1))
@@ -954,14 +954,14 @@ Return a list of ((-take-while `pred` `list`)
(-drop-while `pred` `list`)), in n
Split the `list` each time `item` is found.
-Unlike `-partition-by`, the `item` is discarded from the results.
+Unlike [`-partition-by`](#-partition-by-fn-list), the `item` is discarded from
the results.
Empty lists are also removed from the result.
Comparison is done by `equal`.
-See also `-split-when`
+See also [`-split-when`](#-split-when-fn-list)
-```cl
+```el
(-split-on '| '(Nil | Leaf a | Node [Tree a])) ;; => '((Nil) (Leaf a) (Node
[Tree a]))
(-split-on ':endgroup '("a" "b" :endgroup "c" :endgroup "d" "e")) ;; => '(("a"
"b") ("c") ("d" "e"))
(-split-on ':endgroup '("a" "b" :endgroup :endgroup "d" "e")) ;; => '(("a"
"b") ("d" "e"))
@@ -971,13 +971,13 @@ See also `-split-when`
Split the `list` on each element where `fn` returns non-nil.
-Unlike `-partition-by`, the "matched" element is discarded from
+Unlike [`-partition-by`](#-partition-by-fn-list), the "matched" element is
discarded from
the results. Empty lists are also removed from the result.
This function can be thought of as a generalization of
`split-string`.
-```cl
+```el
(-split-when 'even? '(1 2 3 4 5 6)) ;; => '((1) (3) (5))
(-split-when 'even? '(1 2 3 4 6 8 9)) ;; => '((1) (3) (9))
(--split-when (memq it '(&optional &rest)) '(a b &optional c d &rest args)) ;;
=> '((a b) (c d) (args))
@@ -987,7 +987,7 @@ This function can be thought of as a generalization of
Return a list of ((-filter `pred` `list`) (-remove `pred` `list`)), in one
pass through the list.
-```cl
+```el
(-separate (lambda (num) (= 0 (% num 2))) '(1 2 3 4 5 6 7)) ;; => '((2 4 6) (1
3 5 7))
(--separate (< it 5) '(3 7 5 9 3 2 1 4 6)) ;; => '((3 3 2 1 4) (7 5 9 6))
(-separate 'cdr '((1 2) (1) (1 2 3) (4))) ;; => '(((1 2) (1 2 3)) ((1) (4)))
@@ -999,7 +999,7 @@ Return a new list with the items in `list` grouped into
`n-`sized sublists.
If there are not enough items to make the last group `n-`sized,
those items are discarded.
-```cl
+```el
(-partition 2 '(1 2 3 4 5 6)) ;; => '((1 2) (3 4) (5 6))
(-partition 2 '(1 2 3 4 5 6 7)) ;; => '((1 2) (3 4) (5 6))
(-partition 3 '(1 2 3 4 5 6 7)) ;; => '((1 2 3) (4 5 6))
@@ -1010,7 +1010,7 @@ those items are discarded.
Return a new list with the items in `list` grouped into `n-`sized sublists.
The last group may contain less than `n` items.
-```cl
+```el
(-partition-all 2 '(1 2 3 4 5 6)) ;; => '((1 2) (3 4) (5 6))
(-partition-all 2 '(1 2 3 4 5 6 7)) ;; => '((1 2) (3 4) (5 6) (7))
(-partition-all 3 '(1 2 3 4 5 6 7)) ;; => '((1 2 3) (4 5 6) (7))
@@ -1022,7 +1022,7 @@ Return a new list with the items in `list` grouped into
`n-`sized sublists at of
If there are not enough items to make the last group `n-`sized,
those items are discarded.
-```cl
+```el
(-partition-in-steps 2 1 '(1 2 3 4)) ;; => '((1 2) (2 3) (3 4))
(-partition-in-steps 3 2 '(1 2 3 4)) ;; => '((1 2 3))
(-partition-in-steps 3 2 '(1 2 3 4 5)) ;; => '((1 2 3) (3 4 5))
@@ -1033,7 +1033,7 @@ those items are discarded.
Return a new list with the items in `list` grouped into `n-`sized sublists at
offsets `step` apart.
The last groups may contain less than `n` items.
-```cl
+```el
(-partition-all-in-steps 2 1 '(1 2 3 4)) ;; => '((1 2) (2 3) (3 4) (4))
(-partition-all-in-steps 3 2 '(1 2 3 4)) ;; => '((1 2 3) (3 4))
(-partition-all-in-steps 3 2 '(1 2 3 4 5)) ;; => '((1 2 3) (3 4 5) (5))
@@ -1043,7 +1043,7 @@ The last groups may contain less than `n` items.
Apply `fn` to each item in `list`, splitting it each time `fn` returns a new
value.
-```cl
+```el
(-partition-by 'even? '()) ;; => '()
(-partition-by 'even? '(1 1 2 2 2 3 4 6 8)) ;; => '((1 1) (2 2 2) (3) (4 6 8))
(--partition-by (< it 3) '(1 2 3 4 3 2 1)) ;; => '((1 2) (3 4 3) (2 1))
@@ -1056,7 +1056,7 @@ value. Apply `fn` to each item in `list`, splitting it
each time `fn`
returns the header value, but only after seeing at least one
other value (the body).
-```cl
+```el
(--partition-by-header (= it 1) '(1 2 3 1 2 1 2 3 4)) ;; => '((1 2 3) (1 2) (1
2 3 4))
(--partition-by-header (> it 0) '(1 2 0 1 0 1 2 3 0)) ;; => '((1 2 0) (1 0) (1
2 3 0))
(-partition-by-header 'even? '(2 1 1 1 4 1 3 5 6 6 1)) ;; => '((2 1 1 1) (4 1
3 5) (6 6 1))
@@ -1067,7 +1067,7 @@ other value (the body).
Separate `list` into an alist whose keys are `fn` applied to the
elements of `list`. Keys are compared by `equal`.
-```cl
+```el
(-group-by 'even? '()) ;; => '()
(-group-by 'even? '(1 1 2 2 2 3 4 6 8)) ;; => '((nil 1 1 3) (t 2 2 2 4 6 8))
(--group-by (car (split-string it "/")) '("a/b" "c/d" "a/e")) ;; => '(("a"
"a/b" "a/e") ("c" "c/d"))
@@ -1085,7 +1085,7 @@ Return the index of the first element in the given `list`
which
is equal to the query element `elem`, or nil if there is no
such element.
-```cl
+```el
(-elem-index 2 '(6 7 8 2 3 4)) ;; => 3
(-elem-index "bar" '("foo" "bar" "baz")) ;; => 1
(-elem-index '(1 2) '((3) (5 6) (1 2) nil)) ;; => 2
@@ -1096,7 +1096,7 @@ such element.
Return the indices of all elements in `list` equal to the query
element `elem`, in ascending order.
-```cl
+```el
(-elem-indices 2 '(6 7 8 2 3 4 2 1)) ;; => '(3 6)
(-elem-indices "bar" '("foo" "bar" "baz")) ;; => '(1)
(-elem-indices '(1 2) '((3) (1 2) (5 6) (1 2) nil)) ;; => '(1 3)
@@ -1108,7 +1108,7 @@ Take a predicate `pred` and a `list` and return the index
of the
first element in the list satisfying the predicate, or nil if
there is no such element.
-```cl
+```el
(-find-index 'even? '(2 4 1 6 3 3 5 8)) ;; => 0
(--find-index (< 5 it) '(2 4 1 6 3 3 5 8)) ;; => 3
(-find-index (-partial 'string-lessp "baz") '("bar" "foo" "baz")) ;; => 1
@@ -1120,7 +1120,7 @@ Take a predicate `pred` and a `list` and return the index
of the
last element in the list satisfying the predicate, or nil if
there is no such element.
-```cl
+```el
(-find-last-index 'even? '(2 4 1 6 3 3 5 8)) ;; => 7
(--find-last-index (< 5 it) '(2 7 1 6 3 8 5 2)) ;; => 5
(-find-last-index (-partial 'string-lessp "baz") '("q" "foo" "baz")) ;; => 1
@@ -1131,7 +1131,7 @@ there is no such element.
Return the indices of all elements in `list` satisfying the
predicate `pred`, in ascending order.
-```cl
+```el
(-find-indices 'even? '(2 4 1 6 3 3 5 8)) ;; => '(0 1 3 7)
(--find-indices (< 5 it) '(2 4 1 6 3 3 5 8)) ;; => '(3 7)
(-find-indices (-partial 'string-lessp "baz") '("bar" "foo" "baz")) ;; => '(1)
@@ -1143,7 +1143,7 @@ Grade elements of `list` using `comparator` relation,
yielding a
permutation vector such that applying this permutation to `list`
sorts it in ascending order.
-```cl
+```el
(-grade-up '< '(3 1 4 2 1 3 3)) ;; => '(1 4 3 0 5 6 2)
(let ((l '(3 1 4 2 1 3 3))) (-select-by-indices (-grade-up '< l) l)) ;; => '(1
1 2 3 3 3 4)
```
@@ -1154,7 +1154,7 @@ Grade elements of `list` using `comparator` relation,
yielding a
permutation vector such that applying this permutation to `list`
sorts it in descending order.
-```cl
+```el
(-grade-down '< '(3 1 4 2 1 3 3)) ;; => '(2 0 5 6 3 1 4)
(let ((l '(3 1 4 2 1 3 3))) (-select-by-indices (-grade-down '< l) l)) ;; =>
'(4 3 3 3 2 1 1)
```
@@ -1171,7 +1171,7 @@ Return a new list containing the elements of `list1` and
elements of `list2` tha
The test for equality is done with `equal`,
or with `-compare-fn` if that's non-nil.
-```cl
+```el
(-union '(1 2 3) '(3 4 5)) ;; => '(1 2 3 4 5)
(-union '(1 2 3 4) '()) ;; => '(1 2 3 4)
(-union '(1 1 2 2) '(3 2 1)) ;; => '(1 1 2 2 3)
@@ -1183,7 +1183,7 @@ Return a new list with only the members of `list` that
are not in `list2`.
The test for equality is done with `equal`,
or with `-compare-fn` if that's non-nil.
-```cl
+```el
(-difference '() '()) ;; => '()
(-difference '(1 2 3) '(4 5 6)) ;; => '(1 2 3)
(-difference '(1 2 3 4) '(3 4 5 6)) ;; => '(1 2)
@@ -1195,7 +1195,7 @@ Return a new list containing only the elements that are
members of both `list` a
The test for equality is done with `equal`,
or with `-compare-fn` if that's non-nil.
-```cl
+```el
(-intersection '() '()) ;; => '()
(-intersection '(1 2 3) '(4 5 6)) ;; => '()
(-intersection '(1 2 3 4) '(3 4 5 6)) ;; => '(3 4)
@@ -1209,7 +1209,7 @@ or with `-compare-fn` if that's non-nil.
Alias: `-uniq`
-```cl
+```el
(-distinct '()) ;; => '()
(-distinct '(1 2 2 4)) ;; => '(1 2 4)
```
@@ -1225,7 +1225,7 @@ Other list functions not fit to be classified elsewhere.
Rotate `list` `n` places to the right. With `n` negative, rotate to the left.
The time complexity is `o`(n).
-```cl
+```el
(-rotate 3 '(1 2 3 4 5 6 7)) ;; => '(5 6 7 1 2 3 4)
(-rotate -3 '(1 2 3 4 5 6 7)) ;; => '(4 5 6 7 1 2 3)
```
@@ -1235,7 +1235,7 @@ The time complexity is `o`(n).
Return a list with `x` repeated `n` times.
Return nil if `n` is less than 1.
-```cl
+```el
(-repeat 3 :a) ;; => '(:a :a :a)
(-repeat 1 :a) ;; => '(:a)
(-repeat 0 :a) ;; => nil
@@ -1249,7 +1249,7 @@ The last 2 members of `args` are used as the final cons
of the
result so if the final member of `args` is not a list the result is
a dotted list.
-```cl
+```el
(-cons* 1 2) ;; => '(1 . 2)
(-cons* 1 2 3) ;; => '(1 2 . 3)
(-cons* 1) ;; => 1
@@ -1263,7 +1263,7 @@ This is like `cons`, but operates on the end of list.
If `elements` is non nil, append these to the list as well.
-```cl
+```el
(-snoc '(1 2 3) 4) ;; => '(1 2 3 4)
(-snoc '(1 2 3) 4 5 6) ;; => '(1 2 3 4 5 6)
(-snoc '(1 2 3) '(4 5 6)) ;; => '(1 2 3 (4 5 6))
@@ -1273,7 +1273,7 @@ If `elements` is non nil, append these to the list as
well.
Return a new list of all elements in `list` separated by `sep`.
-```cl
+```el
(-interpose "-" '()) ;; => '()
(-interpose "-" '("a")) ;; => '("a")
(-interpose "-" '("a" "b" "c")) ;; => '("a" "-" "b" "-" "c")
@@ -1283,7 +1283,7 @@ Return a new list of all elements in `list` separated by
`sep`.
Return a new list of the first item in each list, then the second etc.
-```cl
+```el
(-interleave '(1 2) '("a" "b")) ;; => '(1 "a" 2 "b")
(-interleave '(1 2) '("a" "b") '("A" "B")) ;; => '(1 "a" "A" 2 "b" "B")
(-interleave '(1 2 3) '("a" "b")) ;; => '(1 "a" 2 "b")
@@ -1299,7 +1299,7 @@ position.
The anaphoric form `--zip-with` binds the elements from `list1` as `it`,
and the elements from `list2` as `other`.
-```cl
+```el
(-zip-with '+ '(1 2 3) '(4 5 6)) ;; => '(5 7 9)
(-zip-with 'cons '(1 2 3) '(4 5 6)) ;; => '((1 . 4) (2 . 5) (3 . 6))
(--zip-with (concat it " and " other) '("Batman" "Jekyll") '("Robin" "Hyde"))
;; => '("Batman and Robin" "Jekyll and Hyde")
@@ -1314,7 +1314,7 @@ groupings are equal to the length of the shortest input
list.
If two lists are provided as arguments, return the groupings as a list
of cons cells. Otherwise, return the groupings as a list of lists.
-```cl
+```el
(-zip '(1 2 3) '(4 5 6)) ;; => '((1 . 4) (2 . 5) (3 . 6))
(-zip '(1 2 3) '(4 5 6 7)) ;; => '((1 . 4) (2 . 5) (3 . 6))
(-zip '(1 2 3 4) '(4 5 6)) ;; => '((1 . 4) (2 . 5) (3 . 6))
@@ -1326,7 +1326,7 @@ Zip `lists`, with `fill-value` padded onto the shorter
lists. The
lengths of the returned groupings are equal to the length of the
longest input list.
-```cl
+```el
(-zip-fill 0 '(1 2 3 4 5) '(6 7 8 9)) ;; => '((1 . 6) (2 . 7) (3 . 8) (4 . 9)
(5 . 0))
```
@@ -1335,7 +1335,7 @@ longest input list.
Return an infinite copy of `list` that will cycle through the
elements and repeat from the beginning.
-```cl
+```el
(-take 5 (-cycle '(1 2 3))) ;; => '(1 2 3 1 2)
(-take 7 (-cycle '(1 "and" 3))) ;; => '(1 "and" 3 1 "and" 3 1)
(-zip (-cycle '(1 2 3)) '(1 2)) ;; => '((1 . 1) (2 . 2))
@@ -1346,7 +1346,7 @@ elements and repeat from the beginning.
Appends `fill-value` to the end of each list in `lists` such that they
will all have the same length.
-```cl
+```el
(-pad 0 '()) ;; => '(nil)
(-pad 0 '(1)) ;; => '((1))
(-pad 0 '(1 2 3) '(4 5)) ;; => '((1 2 3) (4 5 0))
@@ -1363,9 +1363,9 @@ The outer product is computed by applying fn to all
possible
combinations created by taking one element from each list in
order. The dimension of the result is (length lists).
-See also: `-table-flat`
+See also: [`-table-flat`](#-table-flat-fn-rest-lists)
-```cl
+```el
(-table '* '(1 2 3) '(1 2 3)) ;; => '((1 2 3) (2 4 6) (3 6 9))
(-table (lambda (a b) (-sum (-zip-with '* a b))) '((1 2) (3 4)) '((1 3) (2
4))) ;; => '((7 15) (10 22))
(apply '-table 'list (-repeat 3 '(1 2))) ;; => '((((1 1 1) (2 1 1)) ((1 2 1)
(2 2 1))) (((1 1 2) (2 1 2)) ((1 2 2) (2 2 2))))
@@ -1387,9 +1387,9 @@ of the result. This is equivalent to calling:
but the implementation here is much more efficient.
-See also: `-flatten-n`, `-table`
+See also: [`-flatten-n`](#-flatten-n-num-list),
[`-table`](#-table-fn-rest-lists)
-```cl
+```el
(-table-flat 'list '(1 2 3) '(a b c)) ;; => '((1 a) (2 a) (3 a) (1 b) (2 b) (3
b) (1 c) (2 c) (3 c))
(-table-flat '* '(1 2 3) '(1 2 3)) ;; => '(1 2 3 2 4 6 3 6 9)
(apply '-table-flat 'list (-repeat 3 '(1 2))) ;; => '((1 1 1) (2 1 1) (1 2 1)
(2 2 1) (1 1 2) (2 1 2) (1 2 2) (2 2 2))
@@ -1403,7 +1403,7 @@ To get the first item in the list no questions asked, use
`car`.
Alias: `-find`
-```cl
+```el
(-first 'even? '(1 2 3)) ;; => 2
(-first 'even? '(1 3 5)) ;; => nil
(--first (> it 2) '(1 2 3)) ;; => 3
@@ -1413,7 +1413,7 @@ Alias: `-find`
Return the last x in `list` where (`pred` x) is non-nil, else nil.
-```cl
+```el
(-last 'even? '(1 2 3 4 5 6 3 3 3)) ;; => 6
(-last 'even? '(1 3 7 5 9)) ;; => nil
(--last (> (length it) 3) '("a" "looong" "word" "and" "short" "one")) ;; =>
"short"
@@ -1423,7 +1423,7 @@ Return the last x in `list` where (`pred` x) is non-nil,
else nil.
Return the first item of `list`, or nil on an empty list.
-```cl
+```el
(-first-item '(1 2 3)) ;; => 1
(-first-item nil) ;; => nil
```
@@ -1432,7 +1432,7 @@ Return the first item of `list`, or nil on an empty list.
Return the last item of `list`, or nil on an empty list.
-```cl
+```el
(-last-item '(1 2 3)) ;; => 3
(-last-item nil) ;; => nil
```
@@ -1441,7 +1441,7 @@ Return the last item of `list`, or nil on an empty list.
Return a list of all items in list except for the last.
-```cl
+```el
(-butlast '(1 2 3)) ;; => '(1 2)
(-butlast '(1 2)) ;; => '(1)
(-butlast '(1)) ;; => nil
@@ -1454,7 +1454,7 @@ Return the sorted list. `list` is `not` modified by side
effects.
`comparator` is called with two elements of `list`, and should return non-nil
if the first element should sort before the second.
-```cl
+```el
(-sort '< '(3 1 2)) ;; => '(1 2 3)
(-sort '> '(3 1 2)) ;; => '(3 2 1)
(--sort (< it other) '(3 1 2)) ;; => '(1 2 3)
@@ -1467,7 +1467,7 @@ Return a list with `args`.
If first item of `args` is already a list, simply return `args`. If
not, return a list with `args` as elements.
-```cl
+```el
(-list 1) ;; => '(1)
(-list 1 2 3) ;; => '(1 2 3)
```
@@ -1478,7 +1478,7 @@ Compute the (least) fixpoint of `fn` with initial input
`list`.
`fn` is called at least once, results are compared with `equal`.
-```cl
+```el
(-fix (lambda (l) (-non-nil (--mapcat (-split-at (/ (length it) 2) it) l)))
'((1 2 3 4 5 6))) ;; => '((1) (2) (3) (4) (5) (6))
(let ((data '(("starwars" "scifi") ("jedi" "starwars" "warrior")))) (--fix
(-uniq (--mapcat (cons it (cdr (assoc it data))) it)) '("jedi" "book"))) ;; =>
'("jedi" "starwars" "warrior" "scifi" "book")
```
@@ -1501,7 +1501,7 @@ of the passed branch node.
Non-branch nodes are simply copied.
-```cl
+```el
(-tree-seq 'listp 'identity '(1 (2 3) 4 (5 (6 7)))) ;; => '((1 (2 3) 4 (5 (6
7))) 1 (2 3) 2 3 4 (5 (6 7)) 5 (6 7) 6 7)
(-tree-seq 'listp 'reverse '(1 (2 3) 4 (5 (6 7)))) ;; => '((1 (2 3) 4 (5 (6
7))) (5 (6 7)) (6 7) 7 6 5 4 (2 3) 3 2 1)
(--tree-seq (vectorp it) (append it nil) [1 [2 3] 4 [5 [6 7]]]) ;; => '([1 [2
3] 4 [5 [6 7]]] 1 [2 3] 2 3 4 [5 [6 7]] 5 [6 7] 6 7)
@@ -1511,7 +1511,7 @@ Non-branch nodes are simply copied.
Apply `fn` to each element of `tree` while preserving the tree structure.
-```cl
+```el
(-tree-map '1+ '(1 (2 3) (4 (5 6) 7))) ;; => '(2 (3 4) (5 (6 7) 8))
(-tree-map '(lambda (x) (cons x (expt 2 x))) '(1 (2 3) 4)) ;; => '((1 . 2) ((2
. 4) (3 . 8)) (4 . 16))
(--tree-map (length it) '("<body>" ("<p>" "text" "</p>") "</body>")) ;; => '(6
(3 4 4) 7)
@@ -1525,7 +1525,7 @@ If `pred` returns nil, continue descending down this
node. If `pred`
returns non-nil, apply `fun` to this node and do not descend
further.
-```cl
+```el
(-tree-map-nodes 'vectorp (lambda (x) (-sum (append x nil))) '(1 [2 3] 4 (5 [6
7] 8))) ;; => '(1 5 4 (5 13 8))
(-tree-map-nodes 'keywordp (lambda (x) (symbol-name x)) '(1 :foo 4 ((5 6 :bar)
:baz 8))) ;; => '(1 ":foo" 4 ((5 6 ":bar") ":baz" 8))
(--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)))) ;; => '(with-mode emacs-lisp-mode (foo bar) (add-mode a b
:mode emacs-lisp-mode) (baz (add-mode c d :mode emacs-lisp-mode)))
@@ -1539,9 +1539,9 @@ If elements of `tree` are lists themselves, apply the
reduction recursively.
`fn` is first applied to first element of the list and second
element, then on this result and third element from the list etc.
-See `-reduce-r` for how exactly are lists of zero or one element handled.
+See [`-reduce-r`](#-reduce-r-fn-list) for how exactly are lists of zero or one
element handled.
-```cl
+```el
(-tree-reduce '+ '(1 (2 3) (4 5))) ;; => 15
(-tree-reduce 'concat '("strings" (" on" " various") ((" levels")))) ;; =>
"strings on various levels"
(--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"))) ;; => "<body><p>some words</p>
<div>more <b>bold</b> words</div></body>"
@@ -1558,7 +1558,7 @@ then on this result and second element from the list etc.
The initial value is ignored on cons pairs as they always contain
two elements.
-```cl
+```el
(-tree-reduce-from '+ 1 '(1 (1 1) ((1)))) ;; => 8
(--tree-reduce-from (-concat acc (list it)) nil '(1 (2 3 (4 5)) (6 7))) ;; =>
'((7 6) ((5 4) 3 2) 1)
```
@@ -1570,12 +1570,12 @@ If elements of `tree` are lists themselves, apply `fn`
recursively to
elements of these nested lists.
Then reduce the resulting lists using `folder` and initial value
-`init-value`. See `-reduce-r-from`.
+`init-value`. See [`-reduce-r-from`](#-reduce-r-from-fn-initial-value-list).
-This is the same as calling `-tree-reduce` after `-tree-map`
+This is the same as calling [`-tree-reduce`](#-tree-reduce-fn-tree) after
[`-tree-map`](#-tree-map-fn-tree)
but is twice as fast as it only traverse the structure once.
-```cl
+```el
(-tree-mapreduce 'list 'append '(1 (2 (3 4) (5 6)) (7 (8 9)))) ;; => '(1 2 3 4
5 6 7 8 9)
(--tree-mapreduce 1 (+ it acc) '(1 (2 (4 9) (2 1)) (7 (4 3)))) ;; => 9
(--tree-mapreduce 0 (max acc (1+ it)) '(1 (2 (4 9) (2 1)) (7 (4 3)))) ;; => 3
@@ -1588,12 +1588,12 @@ If elements of `tree` are lists themselves, apply `fn`
recursively to
elements of these nested lists.
Then reduce the resulting lists using `folder` and initial value
-`init-value`. See `-reduce-r-from`.
+`init-value`. See [`-reduce-r-from`](#-reduce-r-from-fn-initial-value-list).
-This is the same as calling `-tree-reduce-from` after `-tree-map`
+This is the same as calling
[`-tree-reduce-from`](#-tree-reduce-from-fn-init-value-tree) after
[`-tree-map`](#-tree-map-fn-tree)
but is twice as fast as it only traverse the structure once.
-```cl
+```el
(-tree-mapreduce-from 'identity '* 1 '(1 (2 (3 4) (5 6)) (7 (8 9)))) ;; =>
362880
(--tree-mapreduce-from (+ it it) (cons it acc) nil '(1 (2 (4 9) (2 1)) (7 (4
3)))) ;; => '(2 (4 (8 18) (4 2)) (14 (8 6)))
(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))))) ;; => "{elips-mode : {foo : {bar ->
booze}, baz -> qux}, c-mode : {foo -> bla, bum -> bam}}"
@@ -1606,7 +1606,7 @@ The new list has the same elements and structure but all
cons are
replaced with new ones. This is useful when you need to clone a
structure such as plist or alist.
-```cl
+```el
(let* ((a '(1 2 3)) (b (-clone a))) (nreverse a) b) ;; => '(1 2 3)
```
@@ -1620,7 +1620,7 @@ in the first form, making a list of it if it is not a list
already. If there are more forms, insert the first form as the
second item in second form, etc.
-```cl
+```el
(-> '(2 3 5)) ;; => '(2 3 5)
(-> '(2 3 5) (append '(8 13))) ;; => '(2 3 5 8 13)
(-> '(2 3 5) (append '(8 13)) (-slice 1 -1)) ;; => '(3 5 8)
@@ -1633,7 +1633,7 @@ in the first form, making a list of it if it is not a list
already. If there are more forms, insert the first form as the
last item in second form, etc.
-```cl
+```el
(->> '(1 2 3) (-map 'square)) ;; => '(1 4 9)
(->> '(1 2 3) (-map 'square) (-remove 'even?)) ;; => '(1 9)
(->> '(1 2 3) (-map 'square) (-reduce '+)) ;; => 14
@@ -1646,7 +1646,7 @@ signified by the token `it` in the first form. If there
are more
forms, insert the first form at the position signified by `it` in
in second form, etc.
-```cl
+```el
(--> "def" (concat "abc" it "ghi")) ;; => "abcdefghi"
(--> "def" (concat "abc" it "ghi") (upcase it)) ;; => "ABCDEFGHI"
(--> "def" (concat "abc" it "ghi") upcase) ;; => "ABCDEFGHI"
@@ -1663,7 +1663,7 @@ Convenient versions of `let` and `let*` constructs
combined with flow control.
If `val` evaluates to non-nil, bind it to `var` and execute body.
`var-val` should be a (`var` `val`) pair.
-```cl
+```el
(-when-let (match-index (string-match "d" "abcd")) (+ match-index 2)) ;; => 5
(--when-let (member :b '(:a :b :c)) (cons :d it)) ;; => '(:d :b :c)
(--when-let (even? 3) (cat it :a)) ;; => nil
@@ -1675,7 +1675,7 @@ If all `vals` evaluate to true, bind them to their
corresponding
`vars` and execute body. `vars-vals` should be a list of (`var` `val`)
pairs (corresponding to bindings of `let*`).
-```cl
+```el
(-when-let* ((x 5) (y 3) (z (+ y 4))) (+ x y z)) ;; => 15
(-when-let* ((x 5) (y nil) (z 7)) (+ x y z)) ;; => nil
```
@@ -1685,7 +1685,7 @@ pairs (corresponding to bindings of `let*`).
If `val` evaluates to non-nil, bind it to `var` and do `then`,
otherwise do `else`. `var-val` should be a (`var` `val`) pair.
-```cl
+```el
(-if-let (match-index (string-match "d" "abc")) (+ match-index 3) 7) ;; => 7
(--if-let (even? 4) it nil) ;; => t
```
@@ -1696,7 +1696,7 @@ If all `vals` evaluate to true, bind them to their
corresponding
`vars` and do `then`, otherwise do `else`. `vars-vals` should be a list
of (`var` `val`) pairs (corresponding to the bindings of `let*`).
-```cl
+```el
(-if-let* ((x 5) (y 3) (z 7)) (+ x y z) "foo") ;; => 15
(-if-let* ((x 5) (y nil) (z 7)) (+ x y z) "foo") ;; => "foo"
```
@@ -1724,7 +1724,7 @@ becomes
(-let [`pattern` `source`] ..).
-`-let` uses a convention of not binding places (symbols) starting
+[`-let`](#-let-varlist-rest-body) uses a convention of not binding places
(symbols) starting
with _ whenever it's possible. You can use this to skip over
entries you don't care about. However, this is not *always*
possible (as a result of implementation) and these symbols might
@@ -1791,7 +1791,7 @@ plist-like key-value pairs, similarly to &keys keyword of
This binds `n` values from the list to a1 ... aN, then interprets
the cdr as a plist (see key/value matching above).
-```cl
+```el
(-let (([a (b c) d] [1 (2 3) 4])) (list a b c d)) ;; => '(1 2 3 4)
(-let [(a b c . d) (list 1 2 3 4 5 6)] (list a b c d)) ;; => '(1 2 3 (4 5 6))
(-let [(&plist :foo foo :bar bar) (list :baz 3 :foo 1 :qux 4 :bar 2)] (list
foo bar)) ;; => '(1 2)
@@ -1809,9 +1809,9 @@ Each `source` can refer to the symbols already bound by
this
`varlist`. This is useful if you want to destructure `source`
recursively but also want to name the intermediate structures.
-See `-let` for the list of all possible patterns.
+See [`-let`](#-let-varlist-rest-body) for the list of all possible patterns.
-```cl
+```el
(-let* (((a . b) (cons 1 2)) ((c . d) (cons 3 4))) (list a b c d)) ;; => '(1 2
3 4)
(-let* (((a . b) (cons 1 (cons 2 3))) ((c . d) b)) (list a b c d)) ;; => '(1
(2 . 3) 2 3)
(-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)) ;; => '(1 a b c (a b c))
@@ -1831,9 +1831,9 @@ has the usual semantics of `lambda`. Furthermore, these
get
translated into normal lambda, so there is no performance
penalty.
-See `-let` for the description of destructuring mechanism.
+See [`-let`](#-let-varlist-rest-body) for the description of destructuring
mechanism.
-```cl
+```el
(-map (-lambda ((x y)) (+ x y)) '((1 2) (3 4) (5 6))) ;; => '(3 7 11)
(-map (-lambda ([x y]) (+ x y)) '([1 2] [3 4] [5 6])) ;; => '(3 7 11)
(funcall (-lambda ((_ . a) (_ . b)) (-concat a b)) '(1 2 3) '(4 5 6)) ;; =>
'(2 3 5 6)
@@ -1849,7 +1849,7 @@ Functions iterating over lists for side-effect only.
Call `fn` with every item in `list`. Return nil, used for side-effects only.
-```cl
+```el
(let (s) (-each '(1 2 3) (lambda (item) (setq s (cons item s))))) ;; => nil
(let (s) (-each '(1 2 3) (lambda (item) (setq s (cons item s)))) s) ;; => '(3
2 1)
(let (s) (--each '(1 2 3) (setq s (cons it s))) s) ;; => '(3 2 1)
@@ -1860,7 +1860,7 @@ Call `fn` with every item in `list`. Return nil, used for
side-effects only.
Call `fn` with every item in `list` while (`pred` item) is non-nil.
Return nil, used for side-effects only.
-```cl
+```el
(let (s) (-each-while '(2 4 5 6) 'even? (lambda (item) (!cons item s))) s) ;;
=> '(4 2)
(let (s) (--each-while '(1 2 3 4) (< it 3) (!cons it s)) s) ;; => '(2 1)
```
@@ -1869,7 +1869,7 @@ Return nil, used for side-effects only.
Repeatedly calls `fn` (presumably for side-effects) passing in integers from 0
through `num-1`.
-```cl
+```el
(let (s) (-dotimes 3 (lambda (n) (!cons n s))) s) ;; => '(2 1 0)
(let (s) (--dotimes 5 (!cons it s)) s) ;; => '(4 3 2 1 0)
```
@@ -1881,7 +1881,7 @@ Repeatedly calls `fn` (presumably for side-effects)
passing in integers from 0 t
Destructive: Set `cdr` to the cons of `car` and `cdr`.
-```cl
+```el
(let (l) (!cons 5 l) l) ;; => '(5)
(let ((l '(3))) (!cons 5 l) l) ;; => '(5 3)
```
@@ -1890,7 +1890,7 @@ Destructive: Set `cdr` to the cons of `car` and `cdr`.
Destructive: Set `list` to the cdr of `list`.
-```cl
+```el
(let ((l '(3))) (!cdr l) l) ;; => '()
(let ((l '(3 5))) (!cdr l) l) ;; => '(5)
```
@@ -1908,7 +1908,7 @@ and returns a fn that takes a variable number of
additional `args`.
When called, the returned function calls `fn` with `args` first and
then additional args.
-```cl
+```el
(funcall (-partial '- 5) 3) ;; => 2
(funcall (-partial '+ 5 2) 3) ;; => 10
```
@@ -1920,7 +1920,7 @@ and returns a fn that takes a variable number of
additional `args`.
When called, the returned function calls `fn` with the additional
args first and then `args`.
-```cl
+```el
(funcall (-rpartial '- 5) 8) ;; => 3
(funcall (-rpartial '- 5 2) 10) ;; => 3
```
@@ -1932,7 +1932,7 @@ juxtaposition of those fns. The returned fn takes a
variable
number of args, and returns a list containing the result of
applying each fn to the args (left-to-right).
-```cl
+```el
(funcall (-juxt '+ '-) 3 5) ;; => '(8 -2)
(-map (-juxt 'identity 'square) '(1 2 3)) ;; => '((1 1) (2 4) (3 9))
```
@@ -1945,7 +1945,7 @@ number of arguments, and returns the result of applying
each fn to the result of applying the previous fn to
the arguments (right-to-left).
-```cl
+```el
(funcall (-compose 'square '+) 2 3) ;; => (square (+ 2 3))
(funcall (-compose 'identity 'square) 3) ;; => (square 3)
(funcall (-compose 'square 'identity) 3) ;; => (square 3)
@@ -1956,7 +1956,7 @@ the arguments (right-to-left).
Changes an n-arity function `fn` to a 1-arity function that
expects a list with n items as arguments
-```cl
+```el
(-map (-applify '+) '((1 1 1) (1 2 3) (5 5 5))) ;; => '(3 6 15)
(-map (-applify (lambda (a b c) (\` ((\, a) ((\, b) ((\, c))))))) '((1 1 1) (1
2 3) (5 5 5))) ;; => '((1 (1 (1))) (1 (2 (3))) (5 (5 (5))))
(funcall (-applify '<) '(3 6)) ;; => t
@@ -1970,7 +1970,7 @@ results (in the same order).
In types: (b -> b -> c) -> (a -> b) -> a -> a -> c
-```cl
+```el
(-sort (-on '< 'length) '((1 2 3) (1) (1 2))) ;; => '((1) (1 2) (1 2 3))
(-min-by (-on '> 'length) '((1 2 3) (4) (1 2))) ;; => '(4)
(-min-by (-on 'string-lessp 'int-to-string) '(2 100 22)) ;; => 22
@@ -1982,7 +1982,7 @@ Swap the order of arguments for binary function `func`.
In types: (a -> b -> c) -> b -> a -> c
-```cl
+```el
(funcall (-flip '<) 2 1) ;; => t
(funcall (-flip '-) 3 8) ;; => 5
(-sort (-flip '<) '(4 3 6 1)) ;; => '(6 4 3 1)
@@ -1994,7 +1994,7 @@ Return a function that returns `c` ignoring any
additional arguments.
In types: a -> b -> a
-```cl
+```el
(funcall (-const 2) 1 3 "foo") ;; => 2
(-map (-const 1) '("a" "b" "c" "d")) ;; => '(1 1 1 1)
(-sum (-map (-const 1) '("a" "b" "c" "d"))) ;; => 4
@@ -2007,7 +2007,7 @@ Arguments denoted by <> will be left unspecialized.
See `srfi-26` for detailed description.
-```cl
+```el
(funcall (-cut list 1 <> 3 <> 5) 2 4) ;; => '(1 2 3 4 5)
(-map (-cut funcall <> 5) '(1+ 1- (lambda (x) (/ 1.0 x)))) ;; => '(6 4 0.2)
(-filter (-cut < <> 5) '(1 3 5 7 9)) ;; => '(1 3)
@@ -2019,7 +2019,7 @@ Take an unary predicates `pred` and return an unary
predicate
that returns t if `pred` returns nil and nil if `pred` returns
non-nil.
-```cl
+```el
(funcall (-not 'even?) 5) ;; => t
(-filter (-not (-partial '< 4)) '(1 2 3 4 5 6 7 8)) ;; => '(1 2 3 4)
```
@@ -2032,7 +2032,7 @@ the `preds` returns non-nil on x.
In types: [a -> Bool] -> a -> Bool
-```cl
+```el
(-filter (-orfn 'even? (-partial (-flip '<) 5)) '(1 2 3 4 5 6 7 8 9 10)) ;; =>
'(1 2 3 4 6 8 10)
(funcall (-orfn 'stringp 'even?) "foo") ;; => t
```
@@ -2045,7 +2045,7 @@ predicate with argument x that returns non-nil if all of
the
In types: [a -> Bool] -> a -> Bool
-```cl
+```el
(funcall (-andfn (-cut < <> 10) 'even?) 6) ;; => t
(funcall (-andfn (-cut < <> 10) 'even?) 12) ;; => nil
(-filter (-andfn (-not 'even?) (-cut >= 5 <>)) '(1 2 3 4 5 6 7 8 9 10)) ;; =>
'(1 3 5)
@@ -2056,7 +2056,7 @@ In types: [a -> Bool] -> a -> Bool
Return a function `fn` composed `n` times with itself.
`fn` is a unary function. If you need to use a function of higher
-arity, use `-applify` first to turn it into an unary function.
+arity, use [`-applify`](#-applify-fn) first to turn it into an unary function.
With n = 0, this acts as identity function.
@@ -2066,7 +2066,7 @@ This function satisfies the following law:
(funcall (-iteratefn fn n) init) = (-last-item (-iterate fn init (1+ n))).
-```cl
+```el
(funcall (-iteratefn (lambda (x) (* x x)) 3) 2) ;; => 256
(funcall (-iteratefn '1+ 3) 1) ;; => 4
(funcall (-iteratefn 'cdr 3) '(1 2 3 4 5)) ;; => '(4 5)
@@ -2080,7 +2080,7 @@ Return a function that computes the (least) fixpoint of
`fn`.
In types: (a -> a) -> a -> a.
-```cl
+```el
(funcall (-fixfn 'cos) 0.7) ;; => 0.7390851332151607
(funcall (-fixfn (lambda (x) (expt (+ x 10) 0.25))) 2.0) ;; =>
1.8555845286409378
```
@@ -2100,7 +2100,7 @@ This function satisfies the following laws:
(-compose (-prodfn f g ...) (-juxt f' g' ...)) = (-juxt (-compose f f')
(-compose g g') ...)
(-compose (-partial 'nth n) (-prod f1 f2 ...)) = (-compose fn (-partial
'nth n))
-```cl
+```el
(funcall (-prodfn '1+ '1- 'int-to-string) '(1 2 3)) ;; => '(2 1 "3")
(-map (-prodfn '1+ '1-) '((1 2) (3 4) (5 6) (7 8))) ;; => '((2 1) (4 3) (6 5)
(8 7))
(apply '+ (funcall (-prodfn 'length 'string-to-int) '((1 2 3) "15"))) ;; => 18
diff --git a/dev/examples-to-docs.el b/dev/examples-to-docs.el
index eb2ce7d..6d5044e 100644
--- a/dev/examples-to-docs.el
+++ b/dev/examples-to-docs.el
@@ -53,24 +53,31 @@ FUNCTION may reference an elisp function, alias, macro or a
subr."
(defun quote-and-downcase (string)
(format "`%s`" (downcase string)))
-(defun quote-docstring (docstring)
+(defun unquote-and-link (string)
+ (format-link (substring string 1 -1)))
+
+(defun format-link (string-name)
+ (-let* ((name (intern string-name))
+ ((_ signature _ _) (assoc name functions)))
+ (if signature
+ (format "[`%s`](#%s)" name (github-id name signature))
+ (format "`%s`" name))))
+
+(defun format-docstring (docstring)
(let (case-fold-search)
(--> docstring
(replace-regexp-in-string "\\b\\([A-Z][A-Z-]*[0-9]*\\)\\b"
'quote-and-downcase it t)
- (replace-regexp-in-string "`\\([^ ]+\\)'" "`\\1`" it t)
+ (replace-regexp-in-string "`\\([^ ]+\\)'" 'unquote-and-link it t)
(replace-regexp-in-string "^ " " " it))))
(defun function-to-md (function)
(if (stringp function)
(concat "\n" (s-replace "### " "## " function) "\n")
- (let ((command-name (car function))
- (signature (cadr function))
- (docstring (quote-docstring (nth 2 function)))
- (examples (nth 3 function)))
- (format "#### %s `%s`\n\n%s\n\n```cl\n%s\n```\n"
+ (-let [(command-name signature docstring examples) function]
+ (format "#### %s `%s`\n\n%s\n\n```el\n%s\n```\n"
command-name
signature
- docstring
+ (format-docstring docstring)
(mapconcat 'identity (-take 3 examples) "\n")))))
(defun docs--chop-prefix (prefix s)
diff --git a/readme-template.md b/readme-template.md
index 97a8db3..fccdbfb 100644
--- a/readme-template.md
+++ b/readme-template.md
@@ -45,7 +45,7 @@ While `-map` takes a function to map over the list, you can
also use
the anaphoric form with double dashes - which will then be executed
with `it` exposed as the list item. Here's an example:
-```cl
+```el
(-map (lambda (n) (* n n)) '(1 2 3 4)) ;; normal version
(--map (* it it) '(1 2 3 4)) ;; anaphoric version
@@ -53,7 +53,7 @@ with `it` exposed as the list item. Here's an example:
of course the original can also be written like
-```cl
+```el
(defun square (n) (* n n))
(-map 'square '(1 2 3 4))
- [elpa] externals/dash 03b98ca 364/426: Make -if-let and -when-let families destructure their arguments, (continued)
- [elpa] externals/dash 03b98ca 364/426: Make -if-let and -when-let families destructure their arguments, Phillip Lord, 2015/08/04
- [elpa] externals/dash 5e9c1a9 373/426: Add Fredrik Bergroth to the list of contributors, Phillip Lord, 2015/08/04
- [elpa] externals/dash 8707aaf 367/426: Update docs, Phillip Lord, 2015/08/04
- [elpa] externals/dash 63fa64f 368/426: Add links to references in readme, Phillip Lord, 2015/08/04
- [elpa] externals/dash d459b49 374/426: Fix typo, Phillip Lord, 2015/08/04
- [elpa] externals/dash 9e1a667 360/426: Do not map nodes on conses (be consistent with tree map), Phillip Lord, 2015/08/04
- [elpa] externals/dash 7185db8 311/426: [Issue #83] Add `step` to `-slice`, Phillip Lord, 2015/08/04
- [elpa] externals/dash 2b69c14 411/426: Add dash.info and dash.texi to repo, Phillip Lord, 2015/08/04
- [elpa] externals/dash c61fc34 417/426: Add -remove-first/last, -map-first/last, -replace-first/last, Phillip Lord, 2015/08/04
- [elpa] externals/dash fb51f8f 304/426: Merge pull request #88 from steventlamb/topic/zip_cycle_pad, Phillip Lord, 2015/08/04
- [elpa] externals/dash d0c6fc0 371/426: Merge pull request #104 from fbergroth/linkify-docs,
Phillip Lord <=
- [elpa] externals/dash c08fcba 299/426: Fixed documentation of `-last-item'., Phillip Lord, 2015/08/04
- [elpa] externals/dash f96196a 289/426: Merge pull request #75 from Fuco1/prefix, Phillip Lord, 2015/08/04
- [elpa] externals/dash afe2781 388/426: Merge pull request #109 from bbatsov/threading-indentation, Phillip Lord, 2015/08/04
- [elpa] externals/dash 6b64ea7 303/426: Add functions for flexibly zipping uneven lists, Phillip Lord, 2015/08/04
- [elpa] externals/dash cd137e0 310/426: `-slice` should not fill the returned list with nils if to > length, Phillip Lord, 2015/08/04
- [elpa] externals/dash 5219ac0 422/426: [-let] Eliminate useless re-binding of symbols when sources are immutable, Phillip Lord, 2015/08/04
- [elpa] externals/dash a06e66e 382/426: Add test for clean byte compilation, Phillip Lord, 2015/08/04
- [elpa] externals/dash 43dcd37 295/426: Only eval NUM in --dotimes once, Phillip Lord, 2015/08/04
- [elpa] externals/dash 4ecfea6 296/426: Merge pull request #79 from Fuco1/debug-forms, Phillip Lord, 2015/08/04
- [elpa] externals/dash 624c501 306/426: Add `-table` and `-table-flat`, Phillip Lord, 2015/08/04