[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/dash ab99be6 335/426: Add -fix
From: |
Phillip Lord |
Subject: |
[elpa] externals/dash ab99be6 335/426: Add -fix |
Date: |
Tue, 04 Aug 2015 19:38:41 +0000 |
branch: externals/dash
commit ab99be66369d4c9a0138f3226fc13f580dd6ff0c
Author: Matus Goljer <address@hidden>
Commit: Matus Goljer <address@hidden>
Add -fix
---
README.md | 12 ++++++++++++
dash.el | 16 ++++++++++++++++
dev/examples.el | 8 +++++++-
3 files changed, 35 insertions(+), 1 deletions(-)
diff --git a/README.md b/README.md
index d30cd76..2b44acf 100644
--- a/README.md
+++ b/README.md
@@ -186,6 +186,7 @@ Other list functions not fit to be classified elsewhere.
* [-butlast](#-butlast-list) `(list)`
* [-sort](#-sort-comparator-list) `(comparator list)`
* [-list](#-list-rest-args) `(&rest args)`
+* [-fix](#-fix-fn-list) `(fn list)`
### Tree operations
@@ -1467,6 +1468,17 @@ not, return a list with `args` as elements.
(-list 1 2 3) ;; => '(1 2 3)
```
+#### -fix `(fn list)`
+
+Compute the (least) fixpoint of `fn` with initial input `list`.
+
+`fn` is called at least once, results are compared with `equal`.
+
+```cl
+(-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")
+```
+
## Tree operations
diff --git a/dash.el b/dash.el
index 76a8e75..c90d3bf 100644
--- a/dash.el
+++ b/dash.el
@@ -1371,6 +1371,20 @@ N is the length of the returned list."
(declare (debug (form form form)))
`(-iterate (lambda (it) ,form) ,init ,n))
+(defun -fix (fn list)
+ "Compute the (least) fixpoint of FN with initial input LIST.
+
+FN is called at least once, results are compared with `equal'."
+ (let ((re (funcall fn list)))
+ (while (not (equal list re))
+ (setq list re)
+ (setq re (funcall fn re)))
+ re))
+
+(defmacro --fix (form list)
+ "Anaphoric form of `-fix'."
+ `(-fix (lambda (it) ,form) ,list))
+
(defun -unfold (fun seed)
"Build a list from SEED using FUN.
@@ -1734,6 +1748,8 @@ structure such as plist or alist."
"--min-by"
"-iterate"
"--iterate"
+ "-fix"
+ "--fix"
"-unfold"
"--unfold"
"-cons-pair?"
diff --git a/dev/examples.el b/dev/examples.el
index 5e1197d..04fb8c3 100644
--- a/dev/examples.el
+++ b/dev/examples.el
@@ -572,7 +572,13 @@ new list."
(-list 1) => '(1)
(-list 1 2 3) => '(1 2 3)
(-list '(1 2 3) => '(1 2 3))
- (-list '((1) (2)) => '((1) (2)))))
+ (-list '((1) (2)) => '((1) (2))))
+
+ (defexamples -fix
+ (-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")))
(def-example-group "Tree operations"
"Functions pretending lists are trees."
- [elpa] externals/dash 38307e3 223/426: Partition docs, (continued)
- [elpa] externals/dash 38307e3 223/426: Partition docs, Phillip Lord, 2015/08/04
- [elpa] externals/dash f3b0a55 321/426: Change -predicate-p examples to -predicate? to maintain consistency, Phillip Lord, 2015/08/04
- [elpa] externals/dash 7e4adb5 319/426: Add missing keywords to highlight list, Phillip Lord, 2015/08/04
- [elpa] externals/dash 2ecc073 316/426: Reorder the partition examples to follow more logical order, add tests, Phillip Lord, 2015/08/04
- [elpa] externals/dash eea928a 320/426: Add -replace, Phillip Lord, 2015/08/04
- [elpa] externals/dash d9879e9 329/426: Release 2.8.0, Phillip Lord, 2015/08/04
- [elpa] externals/dash f8873a0 327/426: Update readme-template with changes from last release, Phillip Lord, 2015/08/04
- [elpa] externals/dash 25c114c 330/426: Implementing a shallow copy counterpart to -clone., Phillip Lord, 2015/08/04
- [elpa] externals/dash f257fb9 328/426: Add -butlast, Phillip Lord, 2015/08/04
- [elpa] externals/dash 174747e 323/426: Add -splice and -splice-list, Phillip Lord, 2015/08/04
- [elpa] externals/dash ab99be6 335/426: Add -fix,
Phillip Lord <=
- [elpa] externals/dash b1e585d 337/426: Update copyright notice, Phillip Lord, 2015/08/04
- [elpa] externals/dash 3adad97 334/426: Add -non-nil, Phillip Lord, 2015/08/04
- [elpa] externals/dash 166bccd 333/426: Add -tree-map-nodes, Phillip Lord, 2015/08/04
- [elpa] externals/dash 05fa92f 342/426: [-let] Transpose nreverse/flatten, Phillip Lord, 2015/08/04
- [elpa] externals/dash f0831d3 339/426: Add -lambda, Phillip Lord, 2015/08/04
- [elpa] externals/dash 9ebcce6 325/426: Add some niceties to font-locking of examples, Phillip Lord, 2015/08/04
- [elpa] externals/dash 6fc652d 331/426: Merge pull request #95 from Wilfred/shallow-copy-function, Phillip Lord, 2015/08/04
- [elpa] externals/dash 5637bd6 322/426: Add alias from -find to -first, Phillip Lord, 2015/08/04
- [elpa] externals/dash a4be872 338/426: Add `-let` and `-let*`, Phillip Lord, 2015/08/04
- [elpa] externals/dash 947ffda 341/426: Add support for &rest match for non-list sequences (like . for improper lists), Phillip Lord, 2015/08/04