[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/dash 6f0636f 032/426: Show only three first examples pe
From: |
Phillip Lord |
Subject: |
[elpa] externals/dash 6f0636f 032/426: Show only three first examples per function. |
Date: |
Tue, 04 Aug 2015 19:36:31 +0000 |
branch: externals/dash
commit 6f0636f61ea0484cb6a63a0c862842391783e8f2
Author: Magnar Sveen <address@hidden>
Commit: Magnar Sveen <address@hidden>
Show only three first examples per function.
---
docs.md | 13 ++-----------
examples-to-docs.el | 18 ++++++++++++++++--
examples.el | 22 +++++++++++++---------
3 files changed, 31 insertions(+), 22 deletions(-)
diff --git a/docs.md b/docs.md
index 54e0239..a4762a0 100644
--- a/docs.md
+++ b/docs.md
@@ -16,9 +16,8 @@ item, etc. If `list` contains no items, returns
`initial-value` and
`fn` is not called.
```cl
-(!reduce-from (quote +) 7 (quote nil)) ;; => 7
-(!reduce-from (quote +) 7 (quote (1))) ;; => 8
(!reduce-from (quote +) 7 (quote (1 2))) ;; => 10
+(!reduce-from (lambda (memo item) (+ memo item)) 7 (quote (1 2))) ;; => 10
(!!reduce-from (+ acc it) 7 (quote (1 2 3))) ;; => 13
```
@@ -31,12 +30,9 @@ reduce returns the result of calling `fn` with no arguments.
If
`list` has only 1 item, it is returned and `fn` is not called.
```cl
-(!reduce (quote +) (quote nil)) ;; => 0
-(!reduce (quote +) (quote (1))) ;; => 1
(!reduce (quote +) (quote (1 2))) ;; => 3
(!reduce (lambda (memo item) (format %s-%s memo item)) (quote (1 2 3))) ;; =>
1-2-3
(!!reduce (format %s-%s acc it) (quote (1 2 3))) ;; => 1-2-3
-(!!reduce (format %s-%s acc it) (quote nil)) ;; => nil-nil
```
## !filter `(fn list)`
@@ -57,8 +53,6 @@ Returns a new list of the items in `list` for which `fn`
returns nil.
(!remove (lambda (num) (= 0 (% num 2))) (quote (1 2 3 4))) ;; => (quote (1 3))
(!remove (quote even?) (quote (1 2 3 4))) ;; => (quote (1 3))
(!!remove (= 0 (% it 2)) (quote (1 2 3 4))) ;; => (quote (1 3))
-(let ((mod 2)) (!remove (lambda (num) (= 0 (% num mod))) (quote (1 2 3 4))))
;; => (quote (1 3))
-(let ((mod 2)) (!!remove (= 0 (% it mod)) (quote (1 2 3 4)))) ;; => (quote (1
3))
```
## !concat `(&rest lists)`
@@ -67,7 +61,6 @@ Returns a new list with the concatenation of the elements in
the supplied `lists`.
```cl
-(!concat) ;; => nil
(!concat (quote (1))) ;; => (quote (1))
(!concat (quote (1)) (quote (2))) ;; => (quote (1 2))
(!concat (quote (1)) (quote (2 3)) (quote (4))) ;; => (quote (1 2 3 4))
@@ -140,7 +133,5 @@ or with `!compare-fn` if that's non-nil.
```cl
(!contains? (quote (1 2 3)) 1) ;; => t
(!contains? (quote (1 2 3)) 2) ;; => t
-(!contains? (quote nil) (quote nil)) ;; => nil
-(!contains? (quote nil) 1) ;; => nil
-(!contains? (quote (1 2 4)) 3) ;; => nil
+(!contains? (quote (1 2 3)) 4) ;; => nil
```
diff --git a/examples-to-docs.el b/examples-to-docs.el
index 79d59ec..0ff201a 100644
--- a/examples-to-docs.el
+++ b/examples-to-docs.el
@@ -32,9 +32,23 @@
(let ((command-name (car function))
(signature (cadr function))
(docstring (quote-docstring (cadr (cdr function))))
- (examples (mapconcat 'identity (cadr (cddr function)) "\n")))
- (format "## %s `%s`\n\n%s\n\n```cl\n%s\n```\n" command-name signature
docstring examples)))
+ (examples (cadr (cddr function))))
+ (format "## %s `%s`\n\n%s\n\n```cl\n%s\n```\n"
+ command-name
+ signature
+ docstring
+ (mapconcat 'identity (three-first examples) "\n"))))
(defun create-docs-file ()
(with-temp-file "./docs.md"
(insert (mapconcat 'function-to-md (nreverse functions) "\n"))))
+
+(defun three-first (list)
+ (let (first)
+ (when (car list)
+ (setq first (cons (car list) first))
+ (when (cadr list)
+ (setq first (cons (cadr list) first))
+ (when (car (cddr list))
+ (setq first (cons (car (cddr list)) first)))))
+ (nreverse first)))
diff --git a/examples.el b/examples.el
index dad913e..addad95 100644
--- a/examples.el
+++ b/examples.el
@@ -1,5 +1,8 @@
;; -*- lexical-binding: t -*-
+;; Only the first three examples per function are shown in the docs,
+;; so make those good.
+
(require 'bang)
(defun even? (num) (= 0 (% num 2)))
@@ -11,17 +14,18 @@
(!!map (* it it) '(1 2 3 4)) => '(1 4 9 16))
(defexamples !reduce-from
- (!reduce-from '+ 7 '()) => 7
- (!reduce-from '+ 7 '(1)) => 8
(!reduce-from '+ 7 '(1 2)) => 10
- (!!reduce-from (+ acc it) 7 '(1 2 3)) => 13)
+ (!reduce-from (lambda (memo item) (+ memo item)) 7 '(1 2)) => 10
+ (!!reduce-from (+ acc it) 7 '(1 2 3)) => 13
+ (!reduce-from '+ 7 '()) => 7
+ (!reduce-from '+ 7 '(1)) => 8)
(defexamples !reduce
- (!reduce '+ '()) => 0
- (!reduce '+ '(1)) => 1
(!reduce '+ '(1 2)) => 3
(!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"
+ (!reduce '+ '()) => 0
+ (!reduce '+ '(1)) => 1
(!!reduce (format "%s-%s" acc it) '()) => "nil-nil")
(defexamples !filter
@@ -37,10 +41,10 @@
(let ((mod 2)) (!!remove (= 0 (% it mod)) '(1 2 3 4))) => '(1 3))
(defexamples !concat
- (!concat) => nil
(!concat '(1)) => '(1)
(!concat '(1) '(2)) => '(1 2)
- (!concat '(1) '(2 3) '(4)) => '(1 2 3 4))
+ (!concat '(1) '(2 3) '(4)) => '(1 2 3 4)
+ (!concat) => nil)
(defexamples !mapcat
(!mapcat 'list '(1 2 3)) => '(1 2 3)
@@ -68,6 +72,6 @@
(defexamples !contains?
(!contains? '(1 2 3) 1) => t
(!contains? '(1 2 3) 2) => t
- (!contains? '() '()) => nil
+ (!contains? '(1 2 3) 4) => nil
(!contains? '() 1) => nil
- (!contains? '(1 2 4) 3) => nil)
+ (!contains? '() '()) => nil)
- [elpa] externals/dash ad44aee 009/426: Add more tests., (continued)
- [elpa] externals/dash ad44aee 009/426: Add more tests., Phillip Lord, 2015/08/04
- [elpa] externals/dash f5b16e3 018/426: Make !partial have the same quote-less API as the rest of bang., Phillip Lord, 2015/08/04
- [elpa] externals/dash a02b6c1 021/426: Add note about no 'cl required., Phillip Lord, 2015/08/04
- [elpa] externals/dash 754dd0d 024/426: Create stand-alone anaphoric macros, Phillip Lord, 2015/08/04
- [elpa] externals/dash 9e74cc0 027/426: Remove dead code., Phillip Lord, 2015/08/04
- [elpa] externals/dash 8eab3d1 028/426: Slight improvements to map., Phillip Lord, 2015/08/04
- [elpa] externals/dash 1997e52 031/426: Treat dashes in docstring better., Phillip Lord, 2015/08/04
- [elpa] externals/dash 52815c5 020/426: Add documentation, Phillip Lord, 2015/08/04
- [elpa] externals/dash d2dfb11 023/426: Use double-bang for anaphoric functions, Phillip Lord, 2015/08/04
- [elpa] externals/dash ed2e447 015/426: !reduce macro, Phillip Lord, 2015/08/04
- [elpa] externals/dash 6f0636f 032/426: Show only three first examples per function.,
Phillip Lord <=
- [elpa] externals/dash c0f2c8f 026/426: Test that it works with lexical binding., Phillip Lord, 2015/08/04
- [elpa] externals/dash 41d77ec 034/426: Add function list to readme., Phillip Lord, 2015/08/04
- [elpa] externals/dash 06efd3c 039/426: Slight improvements to docs., Phillip Lord, 2015/08/04
- [elpa] externals/dash 85016d3 029/426: Fix quoted forms like `' in docs., Phillip Lord, 2015/08/04
- [elpa] externals/dash 214a7db 030/426: Quote and lowercase parameter names in docstring., Phillip Lord, 2015/08/04
- [elpa] externals/dash de5ff6a 037/426: Simplify quotes in readme., Phillip Lord, 2015/08/04
- [elpa] externals/dash 722fea6 033/426: Include docs in README, Phillip Lord, 2015/08/04
- [elpa] externals/dash ec27b47 025/426: Turn tests into examples that can both be tested and turned into docs, Phillip Lord, 2015/08/04
- [elpa] externals/dash 4cc4147 035/426: Fix typo, Phillip Lord, 2015/08/04
- [elpa] externals/dash eea3c53 045/426: Move function list above anaphoric function description., Phillip Lord, 2015/08/04