[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/dash f1c8453 083/439: Rename to dash.
From: |
Phillip Lord |
Subject: |
[elpa] externals/dash f1c8453 083/439: Rename to dash. |
Date: |
Tue, 04 Aug 2015 20:26:40 +0000 |
branch: externals/dash
commit f1c845338cef604efe45ddffc974e961a4c2ef0c
Author: Magnar Sveen <address@hidden>
Commit: Magnar Sveen <address@hidden>
Rename to dash.
---
README.md | 322 ++++++++++++++++++++++++++--------------------------
create-docs.sh | 2 +-
bang.el => dash.el | 240 +++++++++++++++++++-------------------
examples.el | 308 +++++++++++++++++++++++++-------------------------
readme-template.md | 20 ++--
run-tests.sh | 2 +-
6 files changed, 447 insertions(+), 447 deletions(-)
diff --git a/README.md b/README.md
index e044d39..55a1aff 100644
--- a/README.md
+++ b/README.md
@@ -1,60 +1,60 @@
-# bang.el [![Build
Status](https://secure.travis-ci.org/magnars/bang.el.png)](http://travis-ci.org/magnars/bang.el)
+# dash.el [![Build
Status](https://secure.travis-ci.org/magnars/dash.el.png)](http://travis-ci.org/magnars/dash.el)
-The startings of a modern list api for Emacs. No 'cl required.
+A modern list api for Emacs. No 'cl required.
## Installation
It's available on [marmalade](http://marmalade-repo.org/) and
[Melpa](http://melpa.milkbox.net/):
- M-x package-install bang
+ M-x package-install dash
-Or you can just dump `bang.el` in your load path somewhere.
+Or you can just dump `dash.el` in your load path somewhere.
## Functions
-* [!map](#map-fn-list) `(fn list)`
-* [!reduce-from](#reduce-from-fn-initial-value-list) `(fn initial-value list)`
-* [!reduce](#reduce-fn-list) `(fn list)`
-* [!filter](#filter-fn-list) `(fn list)`
-* [!remove](#remove-fn-list) `(fn list)`
-* [!keep](#keep-fn-list) `(fn list)`
-* [!concat](#concat-rest-lists) `(&rest lists)`
-* [!mapcat](#mapcat-fn-list) `(fn list)`
-* [!take](#take-n-list) `(n list)`
-* [!drop](#drop-n-list) `(n list)`
-* [!take-while](#take-while-fn-list) `(fn list)`
-* [!drop-while](#drop-while-fn-list) `(fn list)`
-* [!split-at](#split-at-n-list) `(n list)`
-* [!split-with](#split-with-fn-list) `(fn list)`
-* [!interpose](#interpose-sep-list) `(sep list)`
-* [!replace-where](#replace-where-pred-rep-list) `(pred rep list)`
-* [!first](#first-fn-list) `(fn list)`
-* [!partial](#partial-fn-rest-args) `(fn &rest args)`
-* [!rpartial](#rpartial-fn-rest-args) `(fn &rest args)`
-* [!->](#x-optional-form-rest-more) `(x &optional form &rest more)`
-* [!->>](#x-form-rest-more) `(x form &rest more)`
-* [!!->](#x-form-rest-more) `(x form &rest more)`
-* [!difference](#difference-list-list2) `(list list2)`
-* [!intersection](#intersection-list-list2) `(list list2)`
-* [!distinct](#distinct-list) `(list)`
-* [!contains?](#contains-list-element) `(list element)`
-* [!any?](#any-fn-list) `(fn list)`
-* [!all?](#all-fn-list) `(fn list)`
-* [!each](#each-list-fn) `(list fn)`
+* [-map](#map-fn-list) `(fn list)`
+* [-reduce-from](#reduce-from-fn-initial-value-list) `(fn initial-value list)`
+* [-reduce](#reduce-fn-list) `(fn list)`
+* [-filter](#filter-fn-list) `(fn list)`
+* [-remove](#remove-fn-list) `(fn list)`
+* [-keep](#keep-fn-list) `(fn list)`
+* [-concat](#concat-rest-lists) `(&rest lists)`
+* [-mapcat](#mapcat-fn-list) `(fn list)`
+* [-take](#take-n-list) `(n list)`
+* [-drop](#drop-n-list) `(n list)`
+* [-take-while](#take-while-fn-list) `(fn list)`
+* [-drop-while](#drop-while-fn-list) `(fn list)`
+* [-split-at](#split-at-n-list) `(n list)`
+* [-split-with](#split-with-fn-list) `(fn list)`
+* [-interpose](#interpose-sep-list) `(sep list)`
+* [-replace-where](#replace-where-pred-rep-list) `(pred rep list)`
+* [-first](#first-fn-list) `(fn list)`
+* [-partial](#partial-fn-rest-args) `(fn &rest args)`
+* [-rpartial](#rpartial-fn-rest-args) `(fn &rest args)`
+* [->](#x-optional-form-rest-more) `(x &optional form &rest more)`
+* [->>](#x-form-rest-more) `(x form &rest more)`
+* [-->](#x-form-rest-more) `(x form &rest more)`
+* [-difference](#difference-list-list2) `(list list2)`
+* [-intersection](#intersection-list-list2) `(list list2)`
+* [-distinct](#distinct-list) `(list)`
+* [-contains?](#contains-list-element) `(list element)`
+* [-any?](#any-fn-list) `(fn list)`
+* [-all?](#all-fn-list) `(fn list)`
+* [-each](#each-list-fn) `(list fn)`
There are also anaphoric versions of these functions where that makes sense,
-prefixed with two bangs instead of one.
+prefixed with two dashs instead of one.
## Anaphoric functions
-While `!filter` takes a function to filter the list by, you can also use the
-anaphoric form with double bangs - which will then be executed with `it`
exposed
+While `-filter` takes a function to filter the list by, 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
-(!filter (lambda (num) (= 0 (% num 2))) '(1 2 3 4)) ;; normal version
+(-filter (lambda (num) (= 0 (% num 2))) '(1 2 3 4)) ;; normal version
-(!!filter (= 0 (% it 2)) '(1 2 3 4)) ;; anaphoric version
+(--filter (= 0 (% it 2)) '(1 2 3 4)) ;; anaphoric version
```
of course the original can also be written like
@@ -62,40 +62,40 @@ of course the original can also be written like
```cl
(defun even? (num) (= 0 (% num 2)))
-(!filter 'even? '(1 2 3 4))
+(-filter 'even? '(1 2 3 4))
```
which demonstrates the usefulness of both versions.
## Documentation and examples
-### !map `(fn list)`
+### -map `(fn list)`
Returns a new list consisting of the result of applying `fn` to the items in
`list`.
```cl
-(!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)
+(-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)
```
-### !reduce-from `(fn initial-value list)`
+### -reduce-from `(fn initial-value list)`
Returns the result of applying `fn` to `initial-value` and the
first item in `list`, then applying `fn` to that result and the 2nd
item, etc. If `list` contains no items, returns `initial-value` and
`fn` is not called.
-In the anaphoric form `!!reduce-from`, the accumulated value is
+In the anaphoric form `--reduce-from`, the accumulated value is
exposed as `acc`.
```cl
-(!reduce-from '+ 7 '(1 2)) ;; => 10
-(!reduce-from (lambda (memo item) (+ memo item)) 7 '(1 2)) ;; => 10
-(!!reduce-from (+ acc it) 7 '(1 2 3)) ;; => 13
+(-reduce-from '+ 7 '(1 2)) ;; => 10
+(-reduce-from (lambda (memo item) (+ memo item)) 7 '(1 2)) ;; => 10
+(--reduce-from (+ acc it) 7 '(1 2 3)) ;; => 13
```
-### !reduce `(fn list)`
+### -reduce `(fn list)`
Returns the result of applying `fn` to the first 2 items in `list`,
then applying `fn` to that result and the 3rd item, etc. If `list`
@@ -103,163 +103,163 @@ contains no items, `fn` must accept no arguments as
well, and
reduce returns the result of calling `fn` with no arguments. If
`list` has only 1 item, it is returned and `fn` is not called.
-In the anaphoric form `!!reduce`, the accumulated value is
+In the anaphoric form `--reduce`, the accumulated value is
exposed as `acc`.
```cl
-(!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 '+ '(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"
```
-### !filter `(fn list)`
+### -filter `(fn list)`
Returns a new list of the items in `list` for which `fn` returns a non-nil
value.
-Alias: `!select`
+Alias: `-select`
```cl
-(!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)
+(-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)
```
-### !remove `(fn list)`
+### -remove `(fn list)`
Returns a new list of the items in `list` for which `fn` returns nil.
-Alias: `!reject`
+Alias: `-reject`
```cl
-(!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)
+(-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)
```
-### !keep `(fn list)`
+### -keep `(fn list)`
Returns a new list of the non-nil results of applying `fn` to the items in
`list`.
```cl
-(!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)
+(-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)
```
-### !concat `(&rest lists)`
+### -concat `(&rest lists)`
Returns a new list with the concatenation of the elements in
the supplied `lists`.
```cl
-(!concat '(1)) ;; => '(1)
-(!concat '(1) '(2)) ;; => '(1 2)
-(!concat '(1) '(2 3) '(4)) ;; => '(1 2 3 4)
+(-concat '(1)) ;; => '(1)
+(-concat '(1) '(2)) ;; => '(1 2)
+(-concat '(1) '(2 3) '(4)) ;; => '(1 2 3 4)
```
-### !mapcat `(fn list)`
+### -mapcat `(fn list)`
Returns the result of applying concat to the result of applying map to `fn`
and `list`.
Thus function `fn` should return a collection.
```cl
-(!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)
+(-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)
```
-### !take `(n list)`
+### -take `(n list)`
Returns a new list of the first `n` items in `list`, or all items if there are
fewer than `n`.
```cl
-(!take 3 '(1 2 3 4 5)) ;; => '(1 2 3)
-(!take 17 '(1 2 3 4 5)) ;; => '(1 2 3 4 5)
+(-take 3 '(1 2 3 4 5)) ;; => '(1 2 3)
+(-take 17 '(1 2 3 4 5)) ;; => '(1 2 3 4 5)
```
-### !drop `(n list)`
+### -drop `(n list)`
Returns the tail of `list` without the first `n` items.
```cl
-(!drop 3 '(1 2 3 4 5)) ;; => '(4 5)
-(!drop 17 '(1 2 3 4 5)) ;; => '()
+(-drop 3 '(1 2 3 4 5)) ;; => '(4 5)
+(-drop 17 '(1 2 3 4 5)) ;; => '()
```
-### !take-while `(fn list)`
+### -take-while `(fn list)`
Returns a new list of successive items from `list` while (`fn` item) returns a
non-nil value.
```cl
-(!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)
+(-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)
```
-### !drop-while `(fn list)`
+### -drop-while `(fn list)`
Returns the tail of `list` starting from the first item for which (`fn` item)
returns nil.
```cl
-(!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)
+(-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)
```
-### !split-at `(n list)`
+### -split-at `(n list)`
-Returns a list of ((!take `n` `list`) (!drop `n` `list`))
+Returns a list of ((-take `n` `list`) (-drop `n` `list`))
```cl
-(!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)
+(-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)
```
-### !split-with `(fn list)`
+### -split-with `(fn list)`
-Returns a list of ((!take-while `fn` `list`) (!drop-while `fn` `list`))
+Returns a list of ((-take-while `fn` `list`) (-drop-while `fn` `list`))
```cl
-(!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))
+(-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))
```
-### !interpose `(sep list)`
+### -interpose `(sep list)`
Returns a new list of all elements in `list` separated by `sep`.
```cl
-(!interpose "-" '()) ;; => '()
-(!interpose "-" '("a")) ;; => '("a")
-(!interpose "-" '("a" "b" "c")) ;; => '("a" "-" "b" "-" "c")
+(-interpose "-" '()) ;; => '()
+(-interpose "-" '("a")) ;; => '("a")
+(-interpose "-" '("a" "b" "c")) ;; => '("a" "-" "b" "-" "c")
```
-### !replace-where `(pred rep list)`
+### -replace-where `(pred rep list)`
Returns a new list where the elements in `list` that does not match the `pred`
function
are unchanged, and where the elements in `list` that do match the `pred`
function are mapped
through the `rep` function.
```cl
-(!replace-where 'even? 'square '(1 2 3 4)) ;; => '(1 4 3 16)
-(!!replace-where (> it 2) (* it it) '(1 2 3 4)) ;; => '(1 2 9 16)
-(!!replace-where (= it 2) 17 '(1 2 3 4)) ;; => '(1 17 3 4)
+(-replace-where 'even? 'square '(1 2 3 4)) ;; => '(1 4 3 16)
+(--replace-where (> it 2) (* it it) '(1 2 3 4)) ;; => '(1 2 9 16)
+(--replace-where (= it 2) 17 '(1 2 3 4)) ;; => '(1 17 3 4)
```
-### !first `(fn list)`
+### -first `(fn list)`
Returns the first x in `list` where (`fn` x) is non-nil, else nil.
To get the first item in the list no questions asked, use `car`.
```cl
-(!first 'even? '(1 2 3)) ;; => 2
-(!first 'even? '(1 3 5)) ;; => nil
-(!!first (> it 2) '(1 2 3)) ;; => 3
+(-first 'even? '(1 2 3)) ;; => 2
+(-first 'even? '(1 3 5)) ;; => nil
+(--first (> it 2) '(1 2 3)) ;; => 3
```
-### !partial `(fn &rest args)`
+### -partial `(fn &rest args)`
Takes a function `fn` and fewer than the normal arguments to `fn`,
and returns a fn that takes a variable number of additional `args`.
@@ -267,11 +267,11 @@ When called, the returned function calls `fn` with `args`
first and
then additional args.
```cl
-(funcall (!partial '- 5) 3) ;; => 2
-(funcall (!partial '+ 5 2) 3) ;; => 10
+(funcall (-partial '- 5) 3) ;; => 2
+(funcall (-partial '+ 5 2) 3) ;; => 10
```
-### !rpartial `(fn &rest args)`
+### -rpartial `(fn &rest args)`
Takes a function `fn` and fewer than the normal arguments to `fn`,
and returns a fn that takes a variable number of additional `args`.
@@ -281,11 +281,11 @@ args first and then `args`.
Requires Emacs 24 or higher.
```cl
-(funcall (!rpartial '- 5) 8) ;; => 3
-(funcall (!rpartial '- 5 2) 10) ;; => 3
+(funcall (-rpartial '- 5) 8) ;; => 3
+(funcall (-rpartial '- 5 2) 10) ;; => 3
```
-### !-> `(x &optional form &rest more)`
+### -> `(x &optional form &rest more)`
Threads the expr through the forms. Inserts `x` as the second
item in the first form, making a list of it if it is not a list
@@ -293,12 +293,12 @@ already. If there are more forms, inserts the first form
as the
second item in second form, etc.
```cl
-(!-> "Abc") ;; => "Abc"
-(!-> "Abc" (concat "def")) ;; => "Abcdef"
-(!-> "Abc" (concat "def") (concat "ghi")) ;; => "Abcdefghi"
+(-> "Abc") ;; => "Abc"
+(-> "Abc" (concat "def")) ;; => "Abcdef"
+(-> "Abc" (concat "def") (concat "ghi")) ;; => "Abcdefghi"
```
-### !->> `(x form &rest more)`
+### ->> `(x form &rest more)`
Threads the expr through the forms. Inserts `x` as the last item
in the first form, making a list of it if it is not a list
@@ -306,12 +306,12 @@ already. If there are more forms, inserts the first form
as the
last item in second form, etc.
```cl
-(!->> "Abc" (concat "def")) ;; => "defAbc"
-(!->> "Abc" (concat "def") (concat "ghi")) ;; => "ghidefAbc"
-(!->> 5 (- 8)) ;; => 3
+(->> "Abc" (concat "def")) ;; => "defAbc"
+(->> "Abc" (concat "def") (concat "ghi")) ;; => "ghidefAbc"
+(->> 5 (- 8)) ;; => 3
```
-### !!-> `(x form &rest more)`
+### --> `(x form &rest more)`
Threads the expr through the forms. Inserts `x` at the position
signified by the token `it` in the first form. If there are more
@@ -319,90 +319,90 @@ forms, inserts the first form at the position signified
by `it`
in in second form, etc.
```cl
-(!!-> "def" (concat "abc" it "ghi")) ;; => "abcdefghi"
-(!!-> "def" (concat "abc" it "ghi") (upcase it)) ;; => "ABCDEFGHI"
-(!!-> "def" (concat "abc" it "ghi") upcase) ;; => "ABCDEFGHI"
+(--> "def" (concat "abc" it "ghi")) ;; => "abcdefghi"
+(--> "def" (concat "abc" it "ghi") (upcase it)) ;; => "ABCDEFGHI"
+(--> "def" (concat "abc" it "ghi") upcase) ;; => "ABCDEFGHI"
```
-### !difference `(list list2)`
+### -difference `(list list2)`
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.
+or with `-compare-fn` if that's non-nil.
```cl
-(!difference '() '()) ;; => '()
-(!difference '(1 2 3) '(4 5 6)) ;; => '(1 2 3)
-(!difference '(1 2 3 4) '(3 4 5 6)) ;; => '(1 2)
+(-difference '() '()) ;; => '()
+(-difference '(1 2 3) '(4 5 6)) ;; => '(1 2 3)
+(-difference '(1 2 3 4) '(3 4 5 6)) ;; => '(1 2)
```
-### !intersection `(list list2)`
+### -intersection `(list list2)`
Return a new list containing only the elements that are members of both `list`
and `list2`.
The test for equality is done with `equal`,
-or with `!compare-fn` if that's non-nil.
+or with `-compare-fn` if that's non-nil.
```cl
-(!intersection '() '()) ;; => '()
-(!intersection '(1 2 3) '(4 5 6)) ;; => '()
-(!intersection '(1 2 3 4) '(3 4 5 6)) ;; => '(3 4)
+(-intersection '() '()) ;; => '()
+(-intersection '(1 2 3) '(4 5 6)) ;; => '()
+(-intersection '(1 2 3 4) '(3 4 5 6)) ;; => '(3 4)
```
-### !distinct `(list)`
+### -distinct `(list)`
Return a new list with all duplicates removed.
The test for equality is done with `equal`,
-or with `!compare-fn` if that's non-nil.
+or with `-compare-fn` if that's non-nil.
```cl
-(!distinct '()) ;; => '()
-(!distinct '(1 2 2 4)) ;; => '(1 2 4)
+(-distinct '()) ;; => '()
+(-distinct '(1 2 2 4)) ;; => '(1 2 4)
```
-### !contains? `(list element)`
+### -contains? `(list element)`
Return whether `list` contains `element`.
The test for equality is done with `equal`,
-or with `!compare-fn` if that's non-nil.
+or with `-compare-fn` if that's non-nil.
```cl
-(!contains? '(1 2 3) 1) ;; => t
-(!contains? '(1 2 3) 2) ;; => t
-(!contains? '(1 2 3) 4) ;; => nil
+(-contains? '(1 2 3) 1) ;; => t
+(-contains? '(1 2 3) 2) ;; => t
+(-contains? '(1 2 3) 4) ;; => nil
```
-### !any? `(fn list)`
+### -any? `(fn list)`
Returns t if (`fn` x) is non-nil for any x in `list`, else nil.
-Alias: `!some?`
+Alias: `-some?`
```cl
-(!any? 'even? '(1 2 3)) ;; => t
-(!any? 'even? '(1 3 5)) ;; => nil
-(!!any? (= 0 (% it 2)) '(1 2 3)) ;; => t
+(-any? 'even? '(1 2 3)) ;; => t
+(-any? 'even? '(1 3 5)) ;; => nil
+(--any? (= 0 (% it 2)) '(1 2 3)) ;; => t
```
-### !all? `(fn list)`
+### -all? `(fn list)`
Returns t if (`fn` x) is non-nil for all x in `list`, else nil.
-Alias: `!every?`
+Alias: `-every?`
```cl
-(!all? 'even? '(1 2 3)) ;; => nil
-(!all? 'even? '(2 4 6)) ;; => t
-(!!all? (= 0 (% it 2)) '(2 4 6)) ;; => t
+(-all? 'even? '(1 2 3)) ;; => nil
+(-all? 'even? '(2 4 6)) ;; => t
+(--all? (= 0 (% it 2)) '(2 4 6)) ;; => t
```
-### !each `(list fn)`
+### -each `(list fn)`
Calls `fn` with every item in `list`. Returns nil, used for side-effects only.
```cl
-(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)
+(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)
```
diff --git a/create-docs.sh b/create-docs.sh
index 3bb561e..9489176 100755
--- a/create-docs.sh
+++ b/create-docs.sh
@@ -4,4 +4,4 @@ if [ -z "$EMACS" ] ; then
EMACS="emacs"
fi
-$EMACS -batch -l bang.el -l examples-to-docs.el -l examples.el -f
create-docs-file
+$EMACS -batch -l dash.el -l examples-to-docs.el -l examples.el -f
create-docs-file
diff --git a/bang.el b/dash.el
similarity index 66%
rename from bang.el
rename to dash.el
index aab0a48..9781960 100644
--- a/bang.el
+++ b/dash.el
@@ -1,4 +1,4 @@
-;;; bang.el --- A modern list library for Emacs
+;;; dash.el --- A modern list library for Emacs
;; Copyright (C) 2012 Magnar Sveen
@@ -23,20 +23,20 @@
;; The startings of a modern list api for Emacs.
;;
-;; See documentation on https://github.com/magnars/bang.el#functions
+;; See documentation on https://github.com/magnars/dash.el#functions
;;; Code:
-(defun !map (fn list)
+(defun -map (fn list)
"Returns a new list consisting of the result of applying FN to the items in
LIST."
(mapcar fn list))
-(defmacro !!map (form list)
- "Anaphoric form of `!map'."
+(defmacro --map (form list)
+ "Anaphoric form of `-map'."
`(mapcar (lambda (it) ,form) ,list))
-(defmacro !!reduce-from (form initial-value list)
- "Anaphoric form of `!reduce-from'."
+(defmacro --reduce-from (form initial-value list)
+ "Anaphoric form of `-reduce-from'."
(let ((l (make-symbol "list"))
(a (make-symbol "acc")))
`(let ((,l ,list)
@@ -48,37 +48,37 @@
(setq ,l (cdr ,l)))
,a)))
-(defun !reduce-from (fn initial-value list)
+(defun -reduce-from (fn initial-value list)
"Returns the result of applying FN to INITIAL-VALUE and the
first item in LIST, then applying FN to that result and the 2nd
item, etc. If LIST contains no items, returns INITIAL-VALUE and
FN is not called.
-In the anaphoric form `!!reduce-from', the accumulated value is
+In the anaphoric form `--reduce-from', the accumulated value is
exposed as `acc`."
- (!!reduce-from (funcall fn acc it) initial-value list))
+ (--reduce-from (funcall fn acc it) initial-value list))
-(defmacro !!reduce (form list)
- "Anaphoric form of `!reduce'."
+(defmacro --reduce (form list)
+ "Anaphoric form of `-reduce'."
(if (eval list)
- `(!!reduce-from ,form ,(car (eval list)) ',(cdr (eval list)))
+ `(--reduce-from ,form ,(car (eval list)) ',(cdr (eval list)))
`(let (acc it) ,form)))
-(defun !reduce (fn list)
+(defun -reduce (fn list)
"Returns the result of applying FN to the first 2 items in LIST,
then applying FN to that result and the 3rd item, etc. If LIST
contains no items, FN must accept no arguments as well, and
reduce returns the result of calling FN with no arguments. If
LIST has only 1 item, it is returned and FN is not called.
-In the anaphoric form `!!reduce', the accumulated value is
+In the anaphoric form `--reduce', the accumulated value is
exposed as `acc`."
(if list
- (!reduce-from fn (car list) (cdr list))
+ (-reduce-from fn (car list) (cdr list))
(funcall fn)))
-(defmacro !!filter (form list)
- "Anaphoric form of `!filter'."
+(defmacro --filter (form list)
+ "Anaphoric form of `-filter'."
(let ((l (make-symbol "list"))
(r (make-symbol "result")))
`(let ((,l ,list)
@@ -90,30 +90,30 @@ exposed as `acc`."
(setq ,l (cdr ,l)))
(nreverse ,r))))
-(defun !filter (fn list)
+(defun -filter (fn list)
"Returns a new list of the items in LIST for which FN returns a non-nil
value.
-Alias: `!select'"
- (!!filter (funcall fn it) list))
+Alias: `-select'"
+ (--filter (funcall fn it) list))
-(defalias '!select '!filter)
-(defalias '!!select '!!filter)
+(defalias '-select '-filter)
+(defalias '--select '--filter)
-(defmacro !!remove (form list)
- "Anaphoric form of `!remove'."
- `(!!filter (not ,form) ,list))
+(defmacro --remove (form list)
+ "Anaphoric form of `-remove'."
+ `(--filter (not ,form) ,list))
-(defun !remove (fn list)
+(defun -remove (fn list)
"Returns a new list of the items in LIST for which FN returns nil.
-Alias: `!reject'"
- (!!remove (funcall fn it) list))
+Alias: `-reject'"
+ (--remove (funcall fn it) list))
-(defalias '!reject '!remove)
-(defalias '!!reject '!!remove)
+(defalias '-reject '-remove)
+(defalias '--reject '--remove)
-(defmacro !!keep (form list)
- "Anaphoric form of `!keep'."
+(defmacro --keep (form list)
+ "Anaphoric form of `-keep'."
(let ((l (make-symbol "list"))
(r (make-symbol "result")))
`(let ((,l ,list)
@@ -126,25 +126,25 @@ Alias: `!reject'"
(setq ,l (cdr ,l)))
(nreverse ,r))))
-(defun !keep (fn list)
+(defun -keep (fn list)
"Returns a new list of the non-nil results of applying FN to the items in
LIST."
- (!!keep (funcall fn it) list))
+ (--keep (funcall fn it) list))
-(defun !concat (&rest lists)
+(defun -concat (&rest lists)
"Returns a new list with the concatenation of the elements in
the supplied LISTS."
(apply 'append lists))
-(defmacro !!mapcat (form list)
- "Anaphoric form of `!mapcat'."
- `(apply 'append (!!map ,form ,list)))
+(defmacro --mapcat (form list)
+ "Anaphoric form of `-mapcat'."
+ `(apply 'append (--map ,form ,list)))
-(defun !mapcat (fn list)
+(defun -mapcat (fn list)
"Returns the result of applying concat to the result of applying map to FN
and LIST.
Thus function FN should return a collection."
- (!!mapcat (funcall fn it) list))
+ (--mapcat (funcall fn it) list))
-(defun !take (n list)
+(defun -take (n list)
"Returns a new list of the first N items in LIST, or all items if there are
fewer than N."
(let (result)
(while (and list (> n 0))
@@ -153,15 +153,15 @@ Thus function FN should return a collection."
(setq n (1- n)))
(nreverse result)))
-(defun !drop (n list)
+(defun -drop (n list)
"Returns the tail of LIST without the first N items."
(while (and list (> n 0))
(setq list (cdr list))
(setq n (1- n)))
list)
-(defmacro !!take-while (form list)
- "Anaphoric form of `!take-while'."
+(defmacro --take-while (form list)
+ "Anaphoric form of `-take-while'."
(let ((l (make-symbol "list"))
(r (make-symbol "result")))
`(let ((,l ,list)
@@ -171,37 +171,37 @@ Thus function FN should return a collection."
(setq ,l (cdr ,l)))
(nreverse ,r))))
-(defun !take-while (fn list)
+(defun -take-while (fn list)
"Returns a new list of successive items from LIST while (FN item) returns a
non-nil value."
- (!!take-while (funcall fn it) list))
+ (--take-while (funcall fn it) list))
-(defmacro !!drop-while (form list)
- "Anaphoric form of `!drop-while'."
+(defmacro --drop-while (form list)
+ "Anaphoric form of `-drop-while'."
(let ((l (make-symbol "list")))
`(let ((,l ,list))
(while (and ,l (let ((it (car ,l))) ,form))
(setq ,l (cdr ,l)))
,l)))
-(defun !drop-while (fn list)
+(defun -drop-while (fn list)
"Returns the tail of LIST starting from the first item for which (FN item)
returns nil."
- (!!drop-while (funcall fn it) list))
+ (--drop-while (funcall fn it) list))
-(defun !split-at (n list)
- "Returns a list of ((!take N LIST) (!drop N LIST))"
- (list (!take n list)
- (!drop n list)))
+(defun -split-at (n list)
+ "Returns a list of ((-take N LIST) (-drop N LIST))"
+ (list (-take n list)
+ (-drop n list)))
-(defmacro !!split-with (form list)
- "Anaphoric form of `!split-with'."
- `(list (!!take-while ,form ,list)
- (!!drop-while ,form ,list)))
+(defmacro --split-with (form list)
+ "Anaphoric form of `-split-with'."
+ `(list (--take-while ,form ,list)
+ (--drop-while ,form ,list)))
-(defun !split-with (fn list)
- "Returns a list of ((!take-while FN LIST) (!drop-while FN LIST))"
- (!!split-with (funcall fn it) list))
+(defun -split-with (fn list)
+ "Returns a list of ((-take-while FN LIST) (-drop-while FN LIST))"
+ (--split-with (funcall fn it) list))
-(defun !interpose (sep list)
+(defun -interpose (sep list)
"Returns a new list of all elements in LIST separated by SEP."
(let (result)
(when list
@@ -212,8 +212,8 @@ Thus function FN should return a collection."
(setq list (cdr list)))
(nreverse result)))
-(defmacro !!replace-where (pred rep list)
- "Anaphoric form of `!replace-where'."
+(defmacro --replace-where (pred rep list)
+ "Anaphoric form of `-replace-where'."
(let ((l (make-symbol "list"))
(r (make-symbol "result")))
`(let ((,l ,list)
@@ -224,20 +224,20 @@ Thus function FN should return a collection."
(setq ,l (cdr ,l)))
(nreverse ,r))))
-(defun !replace-where (pred rep list)
+(defun -replace-where (pred rep list)
"Returns a new list where the elements in LIST that does not match the PRED
function
are unchanged, and where the elements in LIST that do match the PRED function
are mapped
through the REP function."
- (!!replace-where (funcall pred it) (funcall rep it) list))
+ (--replace-where (funcall pred it) (funcall rep it) list))
-(defun !partial (fn &rest args)
+(defun -partial (fn &rest args)
"Takes a function FN and fewer than the normal arguments to FN,
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."
(apply 'apply-partially fn args))
-(defun !rpartial (fn &rest args)
+(defun -rpartial (fn &rest args)
"Takes a function FN and fewer than the normal arguments to FN,
and returns a fn that takes a variable number of additional ARGS.
When called, the returned function calls FN with the additional
@@ -247,7 +247,7 @@ Requires Emacs 24 or higher."
`(closure (t) (&rest args)
(apply ',fn (append args ',args))))
-(defmacro !-> (x &optional form &rest more)
+(defmacro -> (x &optional form &rest more)
"Threads the expr through the forms. Inserts X as the second
item in the first form, making a list of it if it is not a list
already. If there are more forms, inserts the first form as the
@@ -257,9 +257,9 @@ second item in second form, etc."
((null more) (if (listp form)
`(,(car form) ,x ,@(cdr form))
(list form x)))
- (:else `(!-> (!-> ,x ,form) ,@more))))
+ (:else `(-> (-> ,x ,form) ,@more))))
-(defmacro !->> (x form &rest more)
+(defmacro ->> (x form &rest more)
"Threads the expr through the forms. Inserts X as the last item
in the first form, making a list of it if it is not a list
already. If there are more forms, inserts the first form as the
@@ -268,62 +268,62 @@ last item in second form, etc."
(if (listp form)
`(,(car form) ,@(cdr form) ,x)
(list form x))
- `(!->> (!->> ,x ,form) ,@more)))
+ `(->> (->> ,x ,form) ,@more)))
-(defmacro !!-> (x form &rest more)
+(defmacro --> (x form &rest more)
"Threads the expr through the forms. Inserts X at the position
signified by the token `it' in the first form. If there are more
forms, inserts the first form at the position signified by `it'
in in second form, etc."
(if (null more)
(if (listp form)
- (!!replace-where (eq it 'it) x form)
+ (--replace-where (eq it 'it) x form)
(list form x))
- `(!!-> (!!-> ,x ,form) ,@more)))
+ `(--> (--> ,x ,form) ,@more)))
-(defun !distinct (list)
+(defun -distinct (list)
"Return a new list with all duplicates removed.
The test for equality is done with `equal',
-or with `!compare-fn' if that's non-nil."
+or with `-compare-fn' if that's non-nil."
(let ((result '()))
(while list
(let ((it (car list)))
- (when (not (!contains? result it))
+ (when (not (-contains? result it))
(setq result (cons it result))))
(setq list (cdr list)))
(nreverse result)))
-(defun !intersection (list list2)
+(defun -intersection (list list2)
"Return a new list containing only the elements that are members of both
LIST and LIST2.
The test for equality is done with `equal',
-or with `!compare-fn' if that's non-nil."
- (!!filter (!contains? list2 it) list))
+or with `-compare-fn' if that's non-nil."
+ (--filter (-contains? list2 it) list))
-(defun !difference (list list2)
+(defun -difference (list list2)
"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."
- (!!filter (not (!contains? list2 it)) list))
+or with `-compare-fn' if that's non-nil."
+ (--filter (not (-contains? list2 it)) list))
-(defun !contains? (list element)
+(defun -contains? (list element)
"Return whether LIST contains ELEMENT.
The test for equality is done with `equal',
-or with `!compare-fn' if that's non-nil."
+or with `-compare-fn' if that's non-nil."
(not
(null
(cond
- ((null !compare-fn) (member element list))
- ((eq !compare-fn 'eq) (memq element list))
- ((eq !compare-fn 'eql) (memql element list))
+ ((null -compare-fn) (member element list))
+ ((eq -compare-fn 'eq) (memq element list))
+ ((eq -compare-fn 'eql) (memql element list))
(t
(let ((lst list))
(while (and lst
- (not (funcall !compare-fn element (car lst))))
+ (not (funcall -compare-fn element (car lst))))
(setq lst (cdr lst)))
lst))))))
-(defmacro !!first (form list)
- "Anaphoric form of `!first'."
+(defmacro --first (form list)
+ "Anaphoric form of `-first'."
(let ((l (make-symbol "list"))
(n (make-symbol "needle")))
`(let ((,l ,list)
@@ -334,30 +334,30 @@ or with `!compare-fn' if that's non-nil."
(setq ,l (cdr ,l)))
,n)))
-(defun !first (fn list)
+(defun -first (fn list)
"Returns the first x in LIST where (FN x) is non-nil, else nil.
To get the first item in the list no questions asked, use `car'."
- (!!first (funcall fn it) list))
+ (--first (funcall fn it) list))
-(defun !--truthy? (val)
+(defun ---truthy? (val)
(not (null val)))
-(defmacro !!any? (form list)
- "Anaphoric form of `!any?'."
- `(!--truthy? (!!first ,form ,list)))
+(defmacro --any? (form list)
+ "Anaphoric form of `-any?'."
+ `(---truthy? (--first ,form ,list)))
-(defun !any? (fn list)
+(defun -any? (fn list)
"Returns t if (FN x) is non-nil for any x in LIST, else nil.
-Alias: `!some?'"
- (!!any? (funcall fn it) list))
+Alias: `-some?'"
+ (--any? (funcall fn it) list))
-(defalias '!some? '!any?)
-(defalias '!!some? '!!any?)
+(defalias '-some? '-any?)
+(defalias '--some? '--any?)
-(defmacro !!all? (form list)
- "Anaphoric form of `!all?'."
+(defmacro --all? (form list)
+ "Anaphoric form of `-all?'."
(let ((l (make-symbol "list"))
(a (make-symbol "all")))
`(let ((,l ,list)
@@ -366,19 +366,19 @@ Alias: `!some?'"
(let ((it (car ,l)))
(setq ,a ,form))
(setq ,l (cdr ,l)))
- (!--truthy? ,a))))
+ (---truthy? ,a))))
-(defun !all? (fn list)
+(defun -all? (fn list)
"Returns t if (FN x) is non-nil for all x in LIST, else nil.
-Alias: `!every?'"
- (!!all? (funcall fn it) list))
+Alias: `-every?'"
+ (--all? (funcall fn it) list))
-(defalias '!every? '!all?)
-(defalias '!!every? '!!all?)
+(defalias '-every? '-all?)
+(defalias '--every? '--all?)
-(defmacro !!each (list form)
- "Anaphoric form of `!each'."
+(defmacro --each (list form)
+ "Anaphoric form of `-each'."
(let ((l (make-symbol "list")))
`(let ((,l ,list))
(while ,l
@@ -386,14 +386,14 @@ Alias: `!every?'"
,form)
(setq ,l (cdr ,l))))))
-(defun !each (list fn)
+(defun -each (list fn)
"Calls FN with every item in LIST. Returns nil, used for side-effects only."
- (!!each list (funcall fn it)))
+ (--each list (funcall fn it)))
-(defvar !compare-fn nil
+(defvar -compare-fn nil
"Tests for equality use this function or `equal' if this is nil.
It should only be set using dynamic scope with a let, like:
-(let ((!compare-fn =)) (!union numbers1 numbers2 numbers3)")
+(let ((-compare-fn =)) (-union numbers1 numbers2 numbers3)")
-(provide 'bang)
-;;; bang.el ends here
+(provide 'dash)
+;;; dash.el ends here
diff --git a/examples.el b/examples.el
index 0a7c828..6f11b60 100644
--- a/examples.el
+++ b/examples.el
@@ -3,165 +3,165 @@
;; Only the first three examples per function are shown in the docs,
;; so make those good.
-(require 'bang)
+(require 'dash)
(defun even? (num) (= 0 (% num 2)))
(defun square (num) (* num num))
(defun three-letters () '("A" "B" "C"))
-(defexamples !map
- (!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)
- (!!map (concat it it) (three-letters)) => '("AA" "BB" "CC"))
-
-(defexamples !reduce-from
- (!reduce-from '+ 7 '(1 2)) => 10
- (!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 '+ '(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
- (!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))
-
-(defexamples !remove
- (!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)
- (let ((mod 2)) (!remove (lambda (num) (= 0 (% num mod))) '(1 2 3 4))) => '(1
3)
- (let ((mod 2)) (!!remove (= 0 (% it mod)) '(1 2 3 4))) => '(1 3))
-
-(defexamples !keep
- (!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))
-
-(defexamples !concat
- (!concat '(1)) => '(1)
- (!concat '(1) '(2)) => '(1 2)
- (!concat '(1) '(2 3) '(4)) => '(1 2 3 4)
- (!concat) => nil)
-
-(defexamples !mapcat
- (!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))
-
-(defexamples !take
- (!take 3 '(1 2 3 4 5)) => '(1 2 3)
- (!take 17 '(1 2 3 4 5)) => '(1 2 3 4 5))
-
-(defexamples !drop
- (!drop 3 '(1 2 3 4 5)) => '(4 5)
- (!drop 17 '(1 2 3 4 5)) => '())
-
-(defexamples !take-while
- (!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))
-
-(defexamples !drop-while
- (!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))
-
-(defexamples !split-at
- (!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))
-
-(defexamples !split-with
- (!split-with 'even? '(1 2 3 4)) => '(() (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)))
-
-(defexamples !interpose
- (!interpose "-" '()) => '()
- (!interpose "-" '("a")) => '("a")
- (!interpose "-" '("a" "b" "c")) => '("a" "-" "b" "-" "c"))
-
-(defexamples !replace-where
- (!replace-where 'even? 'square '(1 2 3 4)) => '(1 4 3 16)
- (!!replace-where (> it 2) (* it it) '(1 2 3 4)) => '(1 2 9 16)
- (!!replace-where (= it 2) 17 '(1 2 3 4)) => '(1 17 3 4)
- (!replace-where (lambda (n) (= n 3)) (lambda (n) 0) '(1 2 3 4)) => '(1 2 0
4))
-
-(defexamples !first
- (!first 'even? '(1 2 3)) => 2
- (!first 'even? '(1 3 5)) => nil
- (!!first (> it 2) '(1 2 3)) => 3)
-
-(defexamples !partial
- (funcall (!partial '- 5) 3) => 2
- (funcall (!partial '+ 5 2) 3) => 10)
+(defexamples -map
+ (-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)
+ (--map (concat it it) (three-letters)) => '("AA" "BB" "CC"))
+
+(defexamples -reduce-from
+ (-reduce-from '+ 7 '(1 2)) => 10
+ (-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 '+ '(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
+ (-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))
+
+(defexamples -remove
+ (-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)
+ (let ((mod 2)) (-remove (lambda (num) (= 0 (% num mod))) '(1 2 3 4))) => '(1
3)
+ (let ((mod 2)) (--remove (= 0 (% it mod)) '(1 2 3 4))) => '(1 3))
+
+(defexamples -keep
+ (-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))
+
+(defexamples -concat
+ (-concat '(1)) => '(1)
+ (-concat '(1) '(2)) => '(1 2)
+ (-concat '(1) '(2 3) '(4)) => '(1 2 3 4)
+ (-concat) => nil)
+
+(defexamples -mapcat
+ (-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))
+
+(defexamples -take
+ (-take 3 '(1 2 3 4 5)) => '(1 2 3)
+ (-take 17 '(1 2 3 4 5)) => '(1 2 3 4 5))
+
+(defexamples -drop
+ (-drop 3 '(1 2 3 4 5)) => '(4 5)
+ (-drop 17 '(1 2 3 4 5)) => '())
+
+(defexamples -take-while
+ (-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))
+
+(defexamples -drop-while
+ (-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))
+
+(defexamples -split-at
+ (-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))
+
+(defexamples -split-with
+ (-split-with 'even? '(1 2 3 4)) => '(() (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)))
+
+(defexamples -interpose
+ (-interpose "-" '()) => '()
+ (-interpose "-" '("a")) => '("a")
+ (-interpose "-" '("a" "b" "c")) => '("a" "-" "b" "-" "c"))
+
+(defexamples -replace-where
+ (-replace-where 'even? 'square '(1 2 3 4)) => '(1 4 3 16)
+ (--replace-where (> it 2) (* it it) '(1 2 3 4)) => '(1 2 9 16)
+ (--replace-where (= it 2) 17 '(1 2 3 4)) => '(1 17 3 4)
+ (-replace-where (lambda (n) (= n 3)) (lambda (n) 0) '(1 2 3 4)) => '(1 2 0
4))
+
+(defexamples -first
+ (-first 'even? '(1 2 3)) => 2
+ (-first 'even? '(1 3 5)) => nil
+ (--first (> it 2) '(1 2 3)) => 3)
+
+(defexamples -partial
+ (funcall (-partial '- 5) 3) => 2
+ (funcall (-partial '+ 5 2) 3) => 10)
(unless (version< emacs-version "24")
- (defexamples !rpartial
- (funcall (!rpartial '- 5) 8) => 3
- (funcall (!rpartial '- 5 2) 10) => 3))
-
-(defexamples !->
- (!-> "Abc") => "Abc"
- (!-> "Abc" (concat "def")) => "Abcdef"
- (!-> "Abc" (concat "def") (concat "ghi")) => "Abcdefghi"
- (!-> 5 square) => 25
- (!-> 5 (+ 3) square) => 64)
-
-(defexamples !->>
- (!->> "Abc" (concat "def")) => "defAbc"
- (!->> "Abc" (concat "def") (concat "ghi")) => "ghidefAbc"
- (!->> 5 (- 8)) => 3
- (!->> 5 (- 3) square) => 4)
-
-(defexamples !!->
- (!!-> "def" (concat "abc" it "ghi")) => "abcdefghi"
- (!!-> "def" (concat "abc" it "ghi") (upcase it)) => "ABCDEFGHI"
- (!!-> "def" (concat "abc" it "ghi") upcase) => "ABCDEFGHI")
-
-(defexamples !difference
- (!difference '() '()) => '()
- (!difference '(1 2 3) '(4 5 6)) => '(1 2 3)
- (!difference '(1 2 3 4) '(3 4 5 6)) => '(1 2))
-
-(defexamples !intersection
- (!intersection '() '()) => '()
- (!intersection '(1 2 3) '(4 5 6)) => '()
- (!intersection '(1 2 3 4) '(3 4 5 6)) => '(3 4))
-
-(defexamples !distinct
- (!distinct '()) => '()
- (!distinct '(1 2 2 4)) => '(1 2 4))
-
-(defexamples !contains?
- (!contains? '(1 2 3) 1) => t
- (!contains? '(1 2 3) 2) => t
- (!contains? '(1 2 3) 4) => nil
- (!contains? '() 1) => nil
- (!contains? '() '()) => nil)
-
-(defexamples !any?
- (!any? 'even? '(1 2 3)) => t
- (!any? 'even? '(1 3 5)) => nil
- (!!any? (= 0 (% it 2)) '(1 2 3)) => t)
-
-(defexamples !all?
- (!all? 'even? '(1 2 3)) => nil
- (!all? 'even? '(2 4 6)) => t
- (!!all? (= 0 (% it 2)) '(2 4 6)) => t)
-
-(defexamples !each
- (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)
- (let (s) (!!each (reverse (three-letters)) (setq s (cons it s))) s) => '("A"
"B" "C")
+ (defexamples -rpartial
+ (funcall (-rpartial '- 5) 8) => 3
+ (funcall (-rpartial '- 5 2) 10) => 3))
+
+(defexamples ->
+ (-> "Abc") => "Abc"
+ (-> "Abc" (concat "def")) => "Abcdef"
+ (-> "Abc" (concat "def") (concat "ghi")) => "Abcdefghi"
+ (-> 5 square) => 25
+ (-> 5 (+ 3) square) => 64)
+
+(defexamples ->>
+ (->> "Abc" (concat "def")) => "defAbc"
+ (->> "Abc" (concat "def") (concat "ghi")) => "ghidefAbc"
+ (->> 5 (- 8)) => 3
+ (->> 5 (- 3) square) => 4)
+
+(defexamples -->
+ (--> "def" (concat "abc" it "ghi")) => "abcdefghi"
+ (--> "def" (concat "abc" it "ghi") (upcase it)) => "ABCDEFGHI"
+ (--> "def" (concat "abc" it "ghi") upcase) => "ABCDEFGHI")
+
+(defexamples -difference
+ (-difference '() '()) => '()
+ (-difference '(1 2 3) '(4 5 6)) => '(1 2 3)
+ (-difference '(1 2 3 4) '(3 4 5 6)) => '(1 2))
+
+(defexamples -intersection
+ (-intersection '() '()) => '()
+ (-intersection '(1 2 3) '(4 5 6)) => '()
+ (-intersection '(1 2 3 4) '(3 4 5 6)) => '(3 4))
+
+(defexamples -distinct
+ (-distinct '()) => '()
+ (-distinct '(1 2 2 4)) => '(1 2 4))
+
+(defexamples -contains?
+ (-contains? '(1 2 3) 1) => t
+ (-contains? '(1 2 3) 2) => t
+ (-contains? '(1 2 3) 4) => nil
+ (-contains? '() 1) => nil
+ (-contains? '() '()) => nil)
+
+(defexamples -any?
+ (-any? 'even? '(1 2 3)) => t
+ (-any? 'even? '(1 3 5)) => nil
+ (--any? (= 0 (% it 2)) '(1 2 3)) => t)
+
+(defexamples -all?
+ (-all? 'even? '(1 2 3)) => nil
+ (-all? 'even? '(2 4 6)) => t
+ (--all? (= 0 (% it 2)) '(2 4 6)) => t)
+
+(defexamples -each
+ (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)
+ (let (s) (--each (reverse (three-letters)) (setq s (cons it s))) s) => '("A"
"B" "C")
)
diff --git a/readme-template.md b/readme-template.md
index 3dc541e..706c212 100644
--- a/readme-template.md
+++ b/readme-template.md
@@ -1,32 +1,32 @@
-# bang.el [![Build
Status](https://secure.travis-ci.org/magnars/bang.el.png)](http://travis-ci.org/magnars/bang.el)
+# dash.el [![Build
Status](https://secure.travis-ci.org/magnars/dash.el.png)](http://travis-ci.org/magnars/dash.el)
-The startings of a modern list api for Emacs. No 'cl required.
+A modern list api for Emacs. No 'cl required.
## Installation
It's available on [marmalade](http://marmalade-repo.org/) and
[Melpa](http://melpa.milkbox.net/):
- M-x package-install bang
+ M-x package-install dash
-Or you can just dump `bang.el` in your load path somewhere.
+Or you can just dump `dash.el` in your load path somewhere.
## Functions
[[ function-list ]]
There are also anaphoric versions of these functions where that makes sense,
-prefixed with two bangs instead of one.
+prefixed with two dashs instead of one.
## Anaphoric functions
-While `!filter` takes a function to filter the list by, you can also use the
-anaphoric form with double bangs - which will then be executed with `it`
exposed
+While `-filter` takes a function to filter the list by, 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
-(!filter (lambda (num) (= 0 (% num 2))) '(1 2 3 4)) ;; normal version
+(-filter (lambda (num) (= 0 (% num 2))) '(1 2 3 4)) ;; normal version
-(!!filter (= 0 (% it 2)) '(1 2 3 4)) ;; anaphoric version
+(--filter (= 0 (% it 2)) '(1 2 3 4)) ;; anaphoric version
```
of course the original can also be written like
@@ -34,7 +34,7 @@ of course the original can also be written like
```cl
(defun even? (num) (= 0 (% num 2)))
-(!filter 'even? '(1 2 3 4))
+(-filter 'even? '(1 2 3 4))
```
which demonstrates the usefulness of both versions.
diff --git a/run-tests.sh b/run-tests.sh
index 5043480..697df4b 100755
--- a/run-tests.sh
+++ b/run-tests.sh
@@ -4,4 +4,4 @@ if [ -z "$EMACS" ] ; then
EMACS="emacs"
fi
-$EMACS -batch -l ert.el -l examples-to-tests.el -l bang.el -l examples.el -f
ert-run-tests-batch-and-exit
+$EMACS -batch -l ert.el -l examples-to-tests.el -l dash.el -l examples.el -f
ert-run-tests-batch-and-exit
- [elpa] externals/dash 38cc9e7 088/439: Simplify -interleave with -none?, (continued)
- [elpa] externals/dash 38cc9e7 088/439: Simplify -interleave with -none?, Phillip Lord, 2015/08/04
- [elpa] externals/dash 4b5e24b 087/439: Docs: move -any? -all? -none? and -each up., Phillip Lord, 2015/08/04
- [elpa] externals/dash 0e5c69b 089/439: Docs: more concise example for anaphoric functions., Phillip Lord, 2015/08/04
- [elpa] externals/dash f8d74ff 091/439: Docs: update example text to match example code., Phillip Lord, 2015/08/04
- [elpa] externals/dash b0da7b2 093/439: Declare macros before using them., Phillip Lord, 2015/08/04
- [elpa] externals/dash 6931d8a 094/439: Remove Melpa from installation while waiting for it to be included., Phillip Lord, 2015/08/04
- [elpa] externals/dash 0c55a4b 090/439: 1.0.0, Phillip Lord, 2015/08/04
- [elpa] externals/dash 0bd26ac 096/439: Add aliases for -p instead of ?, Phillip Lord, 2015/08/04
- [elpa] externals/dash a2941cd 097/439: Typo, Phillip Lord, 2015/08/04
- [elpa] externals/dash dc6f46c 098/439: Simplify docs-generation using dash., Phillip Lord, 2015/08/04
- [elpa] externals/dash f1c8453 083/439: Rename to dash.,
Phillip Lord <=
- [elpa] externals/dash eacb6f2 092/439: Docs: Better generation of github urls., Phillip Lord, 2015/08/04
- [elpa] externals/dash 12ed9f6 100/439: Add destructive operations !cons og !cdr, Phillip Lord, 2015/08/04
- [elpa] externals/dash 79b56cc 101/439: Use --each, !cons and !cdr to simplify implementations., Phillip Lord, 2015/08/04
- [elpa] externals/dash 81a3247 104/439: Let -each and -each-while take multiple forms., Phillip Lord, 2015/08/04
- [elpa] externals/dash ba60707 103/439: Use --each-while to simplify implementations., Phillip Lord, 2015/08/04
- [elpa] externals/dash eb50d17 106/439: Add Melpa back in., Phillip Lord, 2015/08/04
- [elpa] externals/dash 4fedd2e 099/439: Add -partition and -partition-all, Phillip Lord, 2015/08/04
- [elpa] externals/dash 38eed45 095/439: Add rainbow-dash, Phillip Lord, 2015/08/04
- [elpa] externals/dash 49512b9 107/439: Simplify -take and -drop with --dotimes, Phillip Lord, 2015/08/04
- [elpa] externals/dash ed47814 105/439: Add -dotimes, Phillip Lord, 2015/08/04