Upgrade dash

This commit is contained in:
Daniel - 2021-09-04 14:47:04 +02:00
parent e37be56b64
commit 0c28ac9283
No known key found for this signature in database
GPG Key ID: 1C7071A75BB72D64
5 changed files with 482 additions and 298 deletions

View File

@ -1,6 +1,6 @@
(define-package "dash" "20210609.1330" "A modern list library for Emacs" (define-package "dash" "20210826.1149" "A modern list library for Emacs"
'((emacs "24")) '((emacs "24"))
:commit "88d799595e8f1b4154637ce8a3f81b97b0520c1a" :authors :commit "39d067b9fbb2db65fc7a6938bfb21489ad990cb4" :authors
'(("Magnar Sveen" . "magnars@gmail.com")) '(("Magnar Sveen" . "magnars@gmail.com"))
:maintainer :maintainer
'("Magnar Sveen" . "magnars@gmail.com") '("Magnar Sveen" . "magnars@gmail.com")

View File

@ -3,7 +3,7 @@
;; Copyright (C) 2012-2021 Free Software Foundation, Inc. ;; Copyright (C) 2012-2021 Free Software Foundation, Inc.
;; Author: Magnar Sveen <magnars@gmail.com> ;; Author: Magnar Sveen <magnars@gmail.com>
;; Version: 2.18.1 ;; Version: 2.19.1
;; Package-Requires: ((emacs "24")) ;; Package-Requires: ((emacs "24"))
;; Keywords: extensions, lisp ;; Keywords: extensions, lisp
;; Homepage: https://github.com/magnars/dash.el ;; Homepage: https://github.com/magnars/dash.el
@ -854,6 +854,36 @@ This function's anaphoric counterpart is `--some'."
(defalias '-any '-some) (defalias '-any '-some)
(defalias '--any '--some) (defalias '--any '--some)
(defmacro --every (form list)
"Return non-nil if FORM evals to non-nil for all items in LIST.
If so, return the last such result of FORM. Otherwise, once an
item is reached for which FORM yields nil, return nil without
evaluating FORM for any further LIST elements.
Each element of LIST in turn is bound to `it' and its index
within LIST to `it-index' before evaluating FORM.
This macro is like `--every-p', but on success returns the last
non-nil result of FORM instead of just t.
This is the anaphoric counterpart to `-every'."
(declare (debug (form form)))
(let ((a (make-symbol "all")))
`(let ((,a t))
(--each-while ,list (setq ,a ,form))
,a)))
(defun -every (pred list)
"Return non-nil if PRED returns non-nil for all items in LIST.
If so, return the last such result of PRED. Otherwise, once an
item is reached for which PRED returns nil, return nil without
calling PRED on any further LIST elements.
This function is like `-every-p', but on success returns the last
non-nil result of PRED instead of just t.
This function's anaphoric counterpart is `--every'."
(--every (funcall pred it) list))
(defmacro --last (form list) (defmacro --last (form list)
"Anaphoric form of `-last'." "Anaphoric form of `-last'."
(declare (debug (form form))) (declare (debug (form form)))
@ -949,7 +979,7 @@ See also: `-last-item'."
(defmacro --any? (form list) (defmacro --any? (form list)
"Anaphoric form of `-any?'." "Anaphoric form of `-any?'."
(declare (debug (form form))) (declare (debug (form form)))
`(---truthy? (--some ,form ,list))) `(and (--some ,form ,list) t))
(defun -any? (pred list) (defun -any? (pred list)
"Return t if (PRED x) is non-nil for any x in LIST, else nil. "Return t if (PRED x) is non-nil for any x in LIST, else nil.
@ -965,17 +995,34 @@ Alias: `-any-p', `-some?', `-some-p'"
(defalias '--some-p '--any?) (defalias '--some-p '--any?)
(defmacro --all? (form list) (defmacro --all? (form list)
"Anaphoric form of `-all?'." "Return t if FORM evals to non-nil for all items in LIST.
Otherwise, once an item is reached for which FORM yields nil,
return nil without evaluating FORM for any further LIST elements.
Each element of LIST in turn is bound to `it' and its index
within LIST to `it-index' before evaluating FORM.
The similar macro `--every' is more widely useful, since it
returns the last non-nil result of FORM instead of just t on
success.
Alias: `--all-p', `--every-p', `--every?'.
This is the anaphoric counterpart to `-all?'."
(declare (debug (form form))) (declare (debug (form form)))
(let ((a (make-symbol "all"))) `(and (--every ,form ,list) t))
`(let ((,a t))
(--each-while ,list ,a (setq ,a ,form))
(---truthy? ,a))))
(defun -all? (pred list) (defun -all? (pred list)
"Return t if (PRED x) is non-nil for all x in LIST, else nil. "Return t if (PRED X) is non-nil for all X in LIST, else nil.
In the latter case, stop after the first X for which (PRED X) is
nil, without calling PRED on any subsequent elements of LIST.
Alias: `-all-p', `-every?', `-every-p'" The similar function `-every' is more widely useful, since it
returns the last non-nil result of PRED instead of just t on
success.
Alias: `-all-p', `-every-p', `-every?'.
This function's anaphoric counterpart is `--all?'."
(--all? (funcall pred it) list)) (--all? (funcall pred it) list))
(defalias '-every? '-all?) (defalias '-every? '-all?)
@ -1143,14 +1190,15 @@ is done in a single list traversal."
(list (nreverse result) list))) (list (nreverse result) list)))
(defun -rotate (n list) (defun -rotate (n list)
"Rotate LIST N places to the right. With N negative, rotate to the left. "Rotate LIST N places to the right (left if N is negative).
The time complexity is O(n)." The time complexity is O(n)."
(declare (pure t) (side-effect-free t)) (declare (pure t) (side-effect-free t))
(when list (cond ((null list) ())
(let* ((len (length list)) ((zerop n) (copy-sequence list))
(n-mod-len (mod n len)) ((let* ((len (length list))
(new-tail-len (- len n-mod-len))) (n-mod-len (mod n len))
(append (nthcdr new-tail-len list) (-take new-tail-len list))))) (new-tail-len (- len n-mod-len)))
(append (nthcdr new-tail-len list) (-take new-tail-len list))))))
(defun -insert-at (n x list) (defun -insert-at (n x list)
"Return a list with X inserted into LIST at position N. "Return a list with X inserted into LIST at position N.
@ -1747,8 +1795,7 @@ See also: `-select-columns', `-select-by-indices'"
in the first form, making a list of it if it is not a list 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 already. If there are more forms, insert the first form as the
second item in second form, etc." second item in second form, etc."
(declare (debug (form &rest [&or symbolp (sexp &rest form)])) (declare (debug (form &rest [&or symbolp (sexp &rest form)])))
(indent 1))
(cond (cond
((null form) x) ((null form) x)
((null more) (if (listp form) ((null more) (if (listp form)
@ -1761,8 +1808,7 @@ second item in second form, etc."
in the first form, making a list of it if it is not a list 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 already. If there are more forms, insert the first form as the
last item in second form, etc." last item in second form, etc."
(declare (debug ->) (declare (debug ->))
(indent 1))
(cond (cond
((null form) x) ((null form) x)
((null more) (if (listp form) ((null more) (if (listp form)
@ -1776,7 +1822,7 @@ last item in second form, etc."
Insert X at the position signified by the symbol `it' in the first Insert X at the position signified by the symbol `it' in the first
form. If there are more forms, insert the first form at the position form. If there are more forms, insert the first form at the position
signified by `it' in in second form, etc." signified by `it' in in second form, etc."
(declare (debug (form body)) (indent 1)) (declare (debug (form body)))
`(-as-> ,x it ,@forms)) `(-as-> ,x it ,@forms))
(defmacro -as-> (value variable &rest forms) (defmacro -as-> (value variable &rest forms)
@ -1789,9 +1835,9 @@ VARIABLE to the result of the first form, and so forth."
`,value `,value
`(let ((,variable ,value)) `(let ((,variable ,value))
(-as-> ,(if (symbolp (car forms)) (-as-> ,(if (symbolp (car forms))
(list (car forms) variable) (list (car forms) variable)
(car forms)) (car forms))
,variable ,variable
,@(cdr forms))))) ,@(cdr forms)))))
(defmacro -some-> (x &optional form &rest more) (defmacro -some-> (x &optional form &rest more)
@ -1803,7 +1849,7 @@ and when that result is non-nil, through the next form, etc."
(let ((result (make-symbol "result"))) (let ((result (make-symbol "result")))
`(-some-> (-when-let (,result ,x) `(-some-> (-when-let (,result ,x)
(-> ,result ,form)) (-> ,result ,form))
,@more)))) ,@more))))
(defmacro -some->> (x &optional form &rest more) (defmacro -some->> (x &optional form &rest more)
"When expr is non-nil, thread it through the first form (via `->>'), "When expr is non-nil, thread it through the first form (via `->>'),
@ -1814,7 +1860,7 @@ and when that result is non-nil, through the next form, etc."
(let ((result (make-symbol "result"))) (let ((result (make-symbol "result")))
`(-some->> (-when-let (,result ,x) `(-some->> (-when-let (,result ,x)
(->> ,result ,form)) (->> ,result ,form))
,@more)))) ,@more))))
(defmacro -some--> (expr &rest forms) (defmacro -some--> (expr &rest forms)
"Thread EXPR through FORMS via `-->', while the result is non-nil. "Thread EXPR through FORMS via `-->', while the result is non-nil.
@ -2683,9 +2729,7 @@ Alias: `-is-prefix-p'."
Alias: `-is-suffix-p'." Alias: `-is-suffix-p'."
(declare (pure t) (side-effect-free t)) (declare (pure t) (side-effect-free t))
(cond ((null suffix)) (equal suffix (last list (length suffix))))
((setq list (member (car suffix) list))
(equal (cdr suffix) (cdr list)))))
(defun -is-infix? (infix list) (defun -is-infix? (infix list)
"Return non-nil if INFIX is infix of LIST. "Return non-nil if INFIX is infix of LIST.
@ -3067,24 +3111,73 @@ taking 1 argument which is a list of N arguments."
(declare (pure t) (side-effect-free t)) (declare (pure t) (side-effect-free t))
(lambda (args) (apply fn args))) (lambda (args) (apply fn args)))
(defun -on (operator transformer) (defun -on (op trans)
"Return a function of two arguments that first applies "Return a function that calls TRANS on each arg and OP on the results.
TRANSFORMER to each of them and then applies OPERATOR on the The returned function takes a variable number of arguments, calls
results (in the same order). the function TRANS on each one in turn, and then passes those
results as the list of arguments to OP, in the same order.
In types: (b -> b -> c) -> (a -> b) -> a -> a -> c" For example, the following pairs of expressions are morally
(lambda (x y) (funcall operator (funcall transformer x) (funcall transformer y)))) equivalent:
(defun -flip (func) (funcall (-on #\\='+ #\\='1+) 1 2 3) = (+ (1+ 1) (1+ 2) (1+ 3))
"Swap the order of arguments for binary function FUNC. (funcall (-on #\\='+ #\\='1+)) = (+)"
(declare (pure t) (side-effect-free t))
(lambda (&rest args)
;; This unrolling seems to be a relatively cheap way to keep the
;; overhead of `mapcar' + `apply' in check.
(cond ((cddr args)
(apply op (mapcar trans args)))
((cdr args)
(funcall op (funcall trans (car args)) (funcall trans (cadr args))))
(args
(funcall op (funcall trans (car args))))
((funcall op)))))
In types: (a -> b -> c) -> b -> a -> c" (defun -flip (fn)
(lambda (x y) (funcall func y x))) "Return a function that calls FN with its arguments reversed.
The returned function takes the same number of arguments as FN.
For example, the following two expressions are morally
equivalent:
(funcall (-flip #\\='-) 1 2) = (- 2 1)
See also: `-rotate-args'."
(declare (pure t) (side-effect-free t))
(lambda (&rest args) ;; Open-code for speed.
(cond ((cddr args) (apply fn (nreverse args)))
((cdr args) (funcall fn (cadr args) (car args)))
(args (funcall fn (car args)))
((funcall fn)))))
(defun -rotate-args (n fn)
"Return a function that calls FN with args rotated N places to the right.
The returned function takes the same number of arguments as FN,
rotates the list of arguments N places to the right (left if N is
negative) just like `-rotate', and applies FN to the result.
See also: `-flip'."
(declare (pure t) (side-effect-free t))
(if (zerop n)
fn
(let ((even (= (% n 2) 0)))
(lambda (&rest args)
(cond ((cddr args) ;; Open-code for speed.
(apply fn (-rotate n args)))
((cdr args)
(let ((fst (car args))
(snd (cadr args)))
(funcall fn (if even fst snd) (if even snd fst))))
(args
(funcall fn (car args)))
((funcall fn)))))))
(defun -const (c) (defun -const (c)
"Return a function that returns C ignoring any additional arguments. "Return a function that returns C ignoring any additional arguments.
In types: a -> b -> a" In types: a -> b -> a"
(declare (pure t) (side-effect-free t))
(lambda (&rest _) c)) (lambda (&rest _) c))
(defmacro -cut (&rest params) (defmacro -cut (&rest params)
@ -3101,30 +3194,51 @@ See SRFI-26 for detailed description."
`(lambda ,args `(lambda ,args
,(let ((body (--map (if (eq it '<>) (pop args) it) params))) ,(let ((body (--map (if (eq it '<>) (pop args) it) params)))
(if (eq (car params) '<>) (if (eq (car params) '<>)
(cons 'funcall body) (cons #'funcall body)
body))))) body)))))
(defun -not (pred) (defun -not (pred)
"Take a unary predicate PRED and return a unary predicate "Return a predicate that negates the result of PRED.
that returns t if PRED returns nil and nil if PRED returns The returned predicate passes its arguments to PRED. If PRED
non-nil." returns nil, the result is non-nil; otherwise the result is nil.
(lambda (x) (not (funcall pred x))))
See also: `-andfn' and `-orfn'."
(declare (pure t) (side-effect-free t))
(lambda (&rest args) (not (apply pred args))))
(defun -orfn (&rest preds) (defun -orfn (&rest preds)
"Take list of unary predicates PREDS and return a unary "Return a predicate that returns the first non-nil result of PREDS.
predicate with argument x that returns non-nil if at least one of The returned predicate takes a variable number of arguments,
the PREDS returns non-nil on x. passes them to each predicate in PREDS in turn until one of them
returns non-nil, and returns that non-nil result without calling
the remaining PREDS. If all PREDS return nil, or if no PREDS are
given, the returned predicate returns nil.
In types: [a -> Bool] -> a -> Bool" See also: `-andfn' and `-not'."
(lambda (x) (-any? (-cut funcall <> x) preds))) (declare (pure t) (side-effect-free t))
;; Open-code for speed.
(cond ((cdr preds) (lambda (&rest args) (--some (apply it args) preds)))
(preds (car preds))
(#'ignore)))
(defun -andfn (&rest preds) (defun -andfn (&rest preds)
"Take list of unary predicates PREDS and return a unary "Return a predicate that returns non-nil if all PREDS do so.
predicate with argument x that returns non-nil if all of the The returned predicate P takes a variable number of arguments and
PREDS returns non-nil on x. passes them to each predicate in PREDS in turn. If any one of
PREDS returns nil, P also returns nil without calling the
remaining PREDS. If all PREDS return non-nil, P returns the last
such value. If no PREDS are given, P always returns non-nil.
In types: [a -> Bool] -> a -> Bool" See also: `-orfn' and `-not'."
(lambda (x) (-all? (-cut funcall <> x) preds))) (declare (pure t) (side-effect-free t))
;; Open-code for speed.
(cond ((cdr preds) (lambda (&rest args) (--every (apply it args) preds)))
(preds (car preds))
;; As a `pure' function, this runtime check may generate
;; backward-incompatible bytecode for `(-andfn)' at compile-time,
;; but I doubt that's a problem in practice (famous last words).
((fboundp 'always) #'always)
((lambda (&rest _) t))))
(defun -iteratefn (fn n) (defun -iteratefn (fn n)
"Return a function FN composed N times with itself. "Return a function FN composed N times with itself.
@ -3188,18 +3302,18 @@ cdr the final output from HALT-TEST.
In types: (a -> a) -> a -> a." In types: (a -> a) -> a -> a."
(let ((eqfn (or equal-test 'equal)) (let ((eqfn (or equal-test 'equal))
(haltfn (or halt-test (haltfn (or halt-test
(-not (-not
(-counter 0 -fixfn-max-iterations))))) (-counter 0 -fixfn-max-iterations)))))
(lambda (x) (lambda (x)
(let ((re (funcall fn x)) (let ((re (funcall fn x))
(halt? (funcall haltfn x))) (halt? (funcall haltfn x)))
(while (and (not halt?) (not (funcall eqfn x re))) (while (and (not halt?) (not (funcall eqfn x re)))
(setq x re (setq x re
re (funcall fn re) re (funcall fn re)
halt? (funcall haltfn re))) halt? (funcall haltfn re)))
(if halt? (cons 'halted halt?) (if halt? (cons 'halted halt?)
re))))) re)))))
(defun -prodfn (&rest fns) (defun -prodfn (&rest fns)
"Take a list of n functions and return a function that takes a "Take a list of n functions and return a function that takes a

View File

@ -1,6 +1,6 @@
This is dash.info, produced by makeinfo version 6.7 from dash.texi. This is dash.info, produced by makeinfo version 6.7 from dash.texi.
This manual is for Dash version 2.18.1. This manual is for Dash version 2.19.1.
Copyright © 20122021 Free Software Foundation, Inc. Copyright © 20122021 Free Software Foundation, Inc.
@ -22,7 +22,7 @@ File: dash.info, Node: Top, Next: Installation, Up: (dir)
Dash Dash
**** ****
This manual is for Dash version 2.18.1. This manual is for Dash version 2.19.1.
Copyright © 20122021 Free Software Foundation, Inc. Copyright © 20122021 Free Software Foundation, Inc.
@ -110,7 +110,7 @@ File: dash.info, Node: Using in a package, Next: Fontification of special vari
If you use Dash in your own package, be sure to list it as a dependency If you use Dash in your own package, be sure to list it as a dependency
in the librarys headers as follows (*note (elisp)Library Headers::). in the librarys headers as follows (*note (elisp)Library Headers::).
;; Package-Requires: ((dash "2.18.1")) ;; Package-Requires: ((dash "2.19.1"))
 
File: dash.info, Node: Fontification of special variables, Next: Info symbol lookup, Prev: Using in a package, Up: Installation File: dash.info, Node: Fontification of special variables, Next: Info symbol lookup, Prev: Using in a package, Up: Installation
@ -1135,27 +1135,68 @@ File: dash.info, Node: Predicates, Next: Partitioning, Prev: Unfolding, Up:
Reductions of one or more lists to a boolean value. Reductions of one or more lists to a boolean value.
-- Function: -some (pred list)
Return (PRED x) for the first LIST item where (PRED x) is non-nil,
else nil.
Alias: -any.
This functions anaphoric counterpart is --some.
(-some #'stringp '(1 "2" 3))
⇒ t
(--some (string-match-p "x" it) '("foo" "axe" "xor"))
⇒ 1
(--some (= it-index 3) '(0 1 2))
⇒ nil
-- Function: -every (pred list)
Return non-nil if PRED returns non-nil for all items in LIST. If
so, return the last such result of PRED. Otherwise, once an item
is reached for which PRED returns nil, return nil without calling
PRED on any further LIST elements.
This function is like -every-p, but on success returns the last
non-nil result of PRED instead of just t.
This functions anaphoric counterpart is --every.
(-every #'numberp '(1 2 3))
⇒ t
(--every (string-match-p "x" it) '("axe" "xor"))
⇒ 0
(--every (= it it-index) '(0 1 3))
⇒ nil
-- Function: -any? (pred list) -- Function: -any? (pred list)
Return t if (PRED x) is non-nil for any x in LIST, else nil. Return t if (PRED x) is non-nil for any x in LIST, else nil.
Alias: -any-p, -some?, -some-p Alias: -any-p, -some?, -some-p
(-any? 'even? '(1 2 3)) (-any? #'numberp '(nil 0 t))
⇒ t ⇒ t
(-any? 'even? '(1 3 5)) (-any? #'numberp '(nil t t))
⇒ nil ⇒ nil
(-any? 'null '(1 3 5)) (-any? #'null '(1 3 5))
⇒ nil ⇒ nil
-- Function: -all? (pred list) -- Function: -all? (pred list)
Return t if (PRED x) is non-nil for all x in LIST, else nil. Return t if (PRED X) is non-nil for all X in LIST, else nil. In
the latter case, stop after the first X for which (PRED X) is nil,
without calling PRED on any subsequent elements of LIST.
Alias: -all-p, -every?, -every-p The similar function -every (*note -every::) is more widely
useful, since it returns the last non-nil result of PRED instead of
just t on success.
(-all? 'even? '(1 2 3)) Alias: -all-p, -every-p, -every?.
⇒ nil
(-all? 'even? '(2 4 6)) This functions anaphoric counterpart is --all?.
(-all? #'numberp '(1 2 3))
⇒ t ⇒ t
(-all? #'numberp '(2 t 6))
⇒ nil
(--all? (= 0 (% it 2)) '(2 4 6)) (--all? (= 0 (% it 2)) '(2 4 6))
⇒ t ⇒ t
@ -1313,9 +1354,9 @@ Functions partitioning the input list into a list of lists.
(-split-on '| '(Nil | Leaf a | Node [Tree a])) (-split-on '| '(Nil | Leaf a | Node [Tree a]))
⇒ ((Nil) (Leaf a) (Node [Tree a])) ⇒ ((Nil) (Leaf a) (Node [Tree a]))
(-split-on ':endgroup '("a" "b" :endgroup "c" :endgroup "d" "e")) (-split-on :endgroup '("a" "b" :endgroup "c" :endgroup "d" "e"))
⇒ (("a" "b") ("c") ("d" "e")) ⇒ (("a" "b") ("c") ("d" "e"))
(-split-on ':endgroup '("a" "b" :endgroup :endgroup "d" "e")) (-split-on :endgroup '("a" "b" :endgroup :endgroup "d" "e"))
⇒ (("a" "b") ("d" "e")) ⇒ (("a" "b") ("d" "e"))
-- Function: -split-when (fn list) -- Function: -split-when (fn list)
@ -1647,8 +1688,8 @@ File: dash.info, Node: Other list operations, Next: Tree operations, Prev: Se
Other list functions not fit to be classified elsewhere. Other list functions not fit to be classified elsewhere.
-- Function: -rotate (n list) -- Function: -rotate (n list)
Rotate LIST N places to the right. With N negative, rotate to the Rotate LIST N places to the right (left if N is negative). The
left. The time complexity is O(n). time complexity is O(n).
(-rotate 3 '(1 2 3 4 5 6 7)) (-rotate 3 '(1 2 3 4 5 6 7))
⇒ (5 6 7 1 2 3 4) ⇒ (5 6 7 1 2 3 4)
@ -1900,21 +1941,6 @@ Other list functions not fit to be classified elsewhere.
(--first (> it 2) '(1 2 3)) (--first (> it 2) '(1 2 3))
⇒ 3 ⇒ 3
-- Function: -some (pred list)
Return (PRED x) for the first LIST item where (PRED x) is non-nil,
else nil.
Alias: -any.
This functions anaphoric counterpart is --some.
(-some (lambda (s) (string-match-p "x" s)) '("foo" "axe" "xor"))
⇒ 1
(-some (lambda (s) (string-match-p "x" s)) '("foo" "bar" "baz"))
⇒ nil
(--some (member 'foo it) '((foo bar) (baz)))
⇒ (foo bar)
-- Function: -last (pred list) -- Function: -last (pred list)
Return the last x in LIST where (PRED x) is non-nil, else nil. Return the last x in LIST where (PRED x) is non-nil, else nil.
@ -2768,31 +2794,58 @@ Functions that manipulate and compose other functions.
(funcall (-applify #'<) '(3 6)) (funcall (-applify #'<) '(3 6))
⇒ t ⇒ t
-- Function: -on (operator transformer) -- Function: -on (op trans)
Return a function of two arguments that first applies TRANSFORMER Return a function that calls TRANS on each arg and OP on the
to each of them and then applies OPERATOR on the results (in the results. The returned function takes a variable number of
same order). arguments, calls the function TRANS on each one in turn, and then
passes those results as the list of arguments to OP, in the same
order.
In types: (b -> b -> c) -> (a -> b) -> a -> a -> c For example, the following pairs of expressions are morally
equivalent:
(-sort (-on '< 'length) '((1 2 3) (1) (1 2))) (funcall (-on #+ #1+) 1 2 3) = (+ (1+ 1) (1+ 2) (1+ 3)) (funcall
(-on #+ #1+)) = (+)
(-sort (-on #'< #'length) '((1 2 3) (1) (1 2)))
⇒ ((1) (1 2) (1 2 3)) ⇒ ((1) (1 2) (1 2 3))
(-min-by (-on '> 'length) '((1 2 3) (4) (1 2))) (funcall (-on #'min #'string-to-number) "22" "2" "1" "12")
⇒ 1
(-min-by (-on #'> #'length) '((1 2 3) (4) (1 2)))
⇒ (4) ⇒ (4)
(-min-by (-on 'string-lessp 'number-to-string) '(2 100 22))
⇒ 22
-- Function: -flip (func) -- Function: -flip (fn)
Swap the order of arguments for binary function FUNC. Return a function that calls FN with its arguments reversed. The
returned function takes the same number of arguments as FN.
In types: (a -> b -> c) -> b -> a -> c For example, the following two expressions are morally equivalent:
(funcall (-flip '<) 2 1) (funcall (-flip #-) 1 2) = (- 2 1)
⇒ t
(funcall (-flip '-) 3 8) See also: -rotate-args (*note -rotate-args::).
⇒ 5
(-sort (-flip '<) '(4 3 6 1)) (-sort (-flip #'<) '(4 3 6 1))
⇒ (6 4 3 1) ⇒ (6 4 3 1)
(funcall (-flip #'-) 3 2 1 10)
⇒ 4
(funcall (-flip #'1+) 1)
⇒ 2
-- Function: -rotate-args (n fn)
Return a function that calls FN with args rotated N places to the
right. The returned function takes the same number of arguments as
FN, rotates the list of arguments N places to the right (left if N
is negative) just like -rotate (*note -rotate::), and applies FN
to the result.
See also: -flip (*note -flip::).
(funcall (-rotate-args -1 #'list) 1 2 3 4)
⇒ (2 3 4 1)
(funcall (-rotate-args 1 #'-) 1 10 100)
⇒ 89
(funcall (-rotate-args 2 #'list) 3 4 5 1 2)
⇒ (1 2 3 4 5)
-- Function: -const (c) -- Function: -const (c)
Return a function that returns C ignoring any additional arguments. Return a function that returns C ignoring any additional arguments.
@ -2801,9 +2854,9 @@ Functions that manipulate and compose other functions.
(funcall (-const 2) 1 3 "foo") (funcall (-const 2) 1 3 "foo")
⇒ 2 ⇒ 2
(-map (-const 1) '("a" "b" "c" "d")) (mapcar (-const 1) '("a" "b" "c" "d"))
⇒ (1 1 1 1) ⇒ (1 1 1 1)
(-sum (-map (-const 1) '("a" "b" "c" "d"))) (-sum (mapcar (-const 1) '("a" "b" "c" "d")))
⇒ 4 ⇒ 4
-- Macro: -cut (&rest params) -- Macro: -cut (&rest params)
@ -2820,39 +2873,52 @@ Functions that manipulate and compose other functions.
⇒ ((1 2 3) [1 2 3] "\1\2\3") ⇒ ((1 2 3) [1 2 3] "\1\2\3")
-- Function: -not (pred) -- Function: -not (pred)
Take a unary predicate PRED and return a unary predicate that Return a predicate that negates the result of PRED. The returned
returns t if PRED returns nil and nil if PRED returns non-nil. predicate passes its arguments to PRED. If PRED returns nil, the
result is non-nil; otherwise the result is nil.
(funcall (-not 'even?) 5) See also: -andfn (*note -andfn::) and -orfn (*note -orfn::).
(funcall (-not #'numberp) "5")
⇒ t ⇒ t
(-filter (-not (-partial '< 4)) '(1 2 3 4 5 6 7 8)) (-sort (-not #'<) '(5 2 1 0 6))
⇒ (6 5 2 1 0)
(-filter (-not (-partial #'< 4)) '(1 2 3 4 5 6 7 8))
⇒ (1 2 3 4) ⇒ (1 2 3 4)
-- Function: -orfn (&rest preds) -- Function: -orfn (&rest preds)
Take list of unary predicates PREDS and return a unary predicate Return a predicate that returns the first non-nil result of PREDS.
with argument x that returns non-nil if at least one of the PREDS The returned predicate takes a variable number of arguments, passes
returns non-nil on x. them to each predicate in PREDS in turn until one of them returns
non-nil, and returns that non-nil result without calling the
remaining PREDS. If all PREDS return nil, or if no PREDS are
given, the returned predicate returns nil.
In types: [a -> Bool] -> a -> Bool See also: -andfn (*note -andfn::) and -not (*note -not::).
(-filter (-orfn 'even? (-partial (-flip '<) 5)) '(1 2 3 4 5 6 7 8 9 10)) (-filter (-orfn #'natnump #'booleanp) '(1 nil "a" -4 b c t))
⇒ (1 2 3 4 6 8 10) ⇒ (1 nil t)
(funcall (-orfn 'stringp 'even?) "foo") (funcall (-orfn #'symbolp (-cut string-match-p "x" <>)) "axe")
⇒ 1
(funcall (-orfn #'= #'+) 1 1)
⇒ t ⇒ t
-- Function: -andfn (&rest preds) -- Function: -andfn (&rest preds)
Take list of unary predicates PREDS and return a unary predicate Return a predicate that returns non-nil if all PREDS do so. The
with argument x that returns non-nil if all of the PREDS returns returned predicate P takes a variable number of arguments and
non-nil on x. passes them to each predicate in PREDS in turn. If any one of
PREDS returns nil, P also returns nil without calling the remaining
PREDS. If all PREDS return non-nil, P returns the last such value.
If no PREDS are given, P always returns non-nil.
In types: [a -> Bool] -> a -> Bool See also: -orfn (*note -orfn::) and -not (*note -not::).
(funcall (-andfn (-cut < <> 10) 'even?) 6) (-filter (-andfn #'numberp (-cut < <> 5)) '(a 1 b 6 c 2))
t (1 2)
(funcall (-andfn (-cut < <> 10) 'even?) 12) (mapcar (-andfn #'numberp #'1+) '(a 1 b 6))
⇒ nil (nil 2 nil 7)
(-filter (-andfn (-not 'even?) (-cut >= 5 <>)) '(1 2 3 4 5 6 7 8 9 10)) (funcall (-andfn #'= #'+) 1 1)
(1 3 5) 2
-- Function: -iteratefn (fn n) -- Function: -iteratefn (fn n)
Return a function FN composed N times with itself. Return a function FN composed N times with itself.
@ -4231,16 +4297,16 @@ Index
* -->: Threading macros. (line 35) * -->: Threading macros. (line 35)
* ->: Threading macros. (line 9) * ->: Threading macros. (line 9)
* ->>: Threading macros. (line 22) * ->>: Threading macros. (line 22)
* -all?: Predicates. (line 20) * -all?: Predicates. (line 53)
* -andfn: Function combinators. * -andfn: Function combinators.
(line 147) (line 184)
* -annotate: Maps. (line 84) * -annotate: Maps. (line 84)
* -any?: Predicates. (line 8) * -any?: Predicates. (line 41)
* -applify: Function combinators. * -applify: Function combinators.
(line 63) (line 63)
* -as->: Threading macros. (line 49) * -as->: Threading macros. (line 49)
* -butlast: Other list operations. * -butlast: Other list operations.
(line 350) (line 335)
* -clone: Tree operations. (line 122) * -clone: Tree operations. (line 122)
* -common-prefix: Reductions. (line 242) * -common-prefix: Reductions. (line 242)
* -common-suffix: Reductions. (line 252) * -common-suffix: Reductions. (line 252)
@ -4249,14 +4315,14 @@ Index
* -concat: List to list. (line 23) * -concat: List to list. (line 23)
* -cons*: Other list operations. * -cons*: Other list operations.
(line 30) (line 30)
* -cons-pair?: Predicates. (line 126) * -cons-pair?: Predicates. (line 167)
* -const: Function combinators. * -const: Function combinators.
(line 101) (line 128)
* -contains?: Predicates. (line 59) * -contains?: Predicates. (line 100)
* -copy: Maps. (line 139) * -copy: Maps. (line 139)
* -count: Reductions. (line 172) * -count: Reductions. (line 172)
* -cut: Function combinators. * -cut: Function combinators.
(line 113) (line 140)
* -cycle: Other list operations. * -cycle: Other list operations.
(line 180) (line 180)
* -difference: Set operations. (line 20) * -difference: Set operations. (line 20)
@ -4273,8 +4339,9 @@ Index
* -each-while: Side effects. (line 24) * -each-while: Side effects. (line 24)
* -elem-index: Indexing. (line 9) * -elem-index: Indexing. (line 9)
* -elem-indices: Indexing. (line 21) * -elem-indices: Indexing. (line 21)
* -every: Predicates. (line 23)
* -fifth-item: Other list operations. * -fifth-item: Other list operations.
(line 330) (line 315)
* -filter: Sublist selection. (line 8) * -filter: Sublist selection. (line 8)
* -find-index: Indexing. (line 32) * -find-index: Indexing. (line 32)
* -find-indices: Indexing. (line 60) * -find-indices: Indexing. (line 60)
@ -4282,17 +4349,17 @@ Index
* -first: Other list operations. * -first: Other list operations.
(line 246) (line 246)
* -first-item: Other list operations. * -first-item: Other list operations.
(line 287) (line 272)
* -fix: Other list operations. * -fix: Other list operations.
(line 390) (line 375)
* -fixfn: Function combinators. * -fixfn: Function combinators.
(line 184) (line 224)
* -flatten: List to list. (line 34) * -flatten: List to list. (line 34)
* -flatten-n: List to list. (line 56) * -flatten-n: List to list. (line 56)
* -flip: Function combinators. * -flip: Function combinators.
(line 89) (line 95)
* -fourth-item: Other list operations. * -fourth-item: Other list operations.
(line 320) (line 305)
* -grade-down: Indexing. (line 81) * -grade-down: Indexing. (line 81)
* -grade-up: Indexing. (line 71) * -grade-up: Indexing. (line 71)
* -group-by: Partitioning. (line 194) * -group-by: Partitioning. (line 194)
@ -4307,24 +4374,24 @@ Index
* -intersection: Set operations. (line 32) * -intersection: Set operations. (line 32)
* -iota: Other list operations. * -iota: Other list operations.
(line 78) (line 78)
* -is-infix?: Predicates. (line 112) * -is-infix?: Predicates. (line 153)
* -is-prefix?: Predicates. (line 88) * -is-prefix?: Predicates. (line 129)
* -is-suffix?: Predicates. (line 100) * -is-suffix?: Predicates. (line 141)
* -iterate: Unfolding. (line 9) * -iterate: Unfolding. (line 9)
* -iteratefn: Function combinators. * -iteratefn: Function combinators.
(line 161) (line 201)
* -juxt: Function combinators. * -juxt: Function combinators.
(line 37) (line 37)
* -keep: List to list. (line 8) * -keep: List to list. (line 8)
* -lambda: Binding. (line 247) * -lambda: Binding. (line 247)
* -last: Other list operations. * -last: Other list operations.
(line 277) (line 262)
* -last-item: Other list operations. * -last-item: Other list operations.
(line 340) (line 325)
* -let: Binding. (line 61) * -let: Binding. (line 61)
* -let*: Binding. (line 227) * -let*: Binding. (line 227)
* -list: Other list operations. * -list: Other list operations.
(line 373) (line 358)
* -map: Maps. (line 10) * -map: Maps. (line 10)
* -map-first: Maps. (line 38) * -map-first: Maps. (line 38)
* -map-indexed: Maps. (line 66) * -map-indexed: Maps. (line 66)
@ -4336,14 +4403,14 @@ Index
* -min: Reductions. (line 262) * -min: Reductions. (line 262)
* -min-by: Reductions. (line 272) * -min-by: Reductions. (line 272)
* -non-nil: Sublist selection. (line 94) * -non-nil: Sublist selection. (line 94)
* -none?: Predicates. (line 32) * -none?: Predicates. (line 73)
* -not: Function combinators. * -not: Function combinators.
(line 126) (line 153)
* -on: Function combinators. * -on: Function combinators.
(line 75) (line 75)
* -only-some?: Predicates. (line 44) * -only-some?: Predicates. (line 85)
* -orfn: Function combinators. * -orfn: Function combinators.
(line 135) (line 167)
* -pad: Other list operations. * -pad: Other list operations.
(line 191) (line 191)
* -partial: Function combinators. * -partial: Function combinators.
@ -4361,7 +4428,7 @@ Index
* -permutations: Set operations. (line 52) * -permutations: Set operations. (line 52)
* -powerset: Set operations. (line 44) * -powerset: Set operations. (line 44)
* -prodfn: Function combinators. * -prodfn: Function combinators.
(line 218) (line 258)
* -product: Reductions. (line 201) * -product: Reductions. (line 201)
* -reduce: Reductions. (line 53) * -reduce: Reductions. (line 53)
* -reduce-from: Reductions. (line 8) * -reduce-from: Reductions. (line 8)
@ -4385,13 +4452,15 @@ Index
* -replace-last: List to list. (line 96) * -replace-last: List to list. (line 96)
* -rotate: Other list operations. * -rotate: Other list operations.
(line 8) (line 8)
* -rotate-args: Function combinators.
(line 112)
* -rpartial: Function combinators. * -rpartial: Function combinators.
(line 22) (line 22)
* -running-product: Reductions. (line 211) * -running-product: Reductions. (line 211)
* -running-sum: Reductions. (line 190) * -running-sum: Reductions. (line 190)
* -same-items?: Predicates. (line 74) * -same-items?: Predicates. (line 115)
* -second-item: Other list operations. * -second-item: Other list operations.
(line 300) (line 285)
* -select-by-indices: Sublist selection. (line 208) * -select-by-indices: Sublist selection. (line 208)
* -select-column: Sublist selection. (line 238) * -select-column: Sublist selection. (line 238)
* -select-columns: Sublist selection. (line 219) * -select-columns: Sublist selection. (line 219)
@ -4400,13 +4469,12 @@ Index
* -slice: Sublist selection. (line 104) * -slice: Sublist selection. (line 104)
* -snoc: Other list operations. * -snoc: Other list operations.
(line 43) (line 43)
* -some: Other list operations. * -some: Predicates. (line 8)
(line 262)
* -some-->: Threading macros. (line 86) * -some-->: Threading macros. (line 86)
* -some->: Threading macros. (line 62) * -some->: Threading macros. (line 62)
* -some->>: Threading macros. (line 74) * -some->>: Threading macros. (line 74)
* -sort: Other list operations. * -sort: Other list operations.
(line 360) (line 345)
* -splice: Maps. (line 95) * -splice: Maps. (line 95)
* -splice-list: Maps. (line 115) * -splice-list: Maps. (line 115)
* -split-at: Partitioning. (line 8) * -split-at: Partitioning. (line 8)
@ -4423,7 +4491,7 @@ Index
* -take-last: Sublist selection. (line 133) * -take-last: Sublist selection. (line 133)
* -take-while: Sublist selection. (line 175) * -take-while: Sublist selection. (line 175)
* -third-item: Other list operations. * -third-item: Other list operations.
(line 310) (line 295)
* -tree-map: Tree operations. (line 28) * -tree-map: Tree operations. (line 28)
* -tree-map-nodes: Tree operations. (line 39) * -tree-map-nodes: Tree operations. (line 39)
* -tree-mapreduce: Tree operations. (line 84) * -tree-mapreduce: Tree operations. (line 84)
@ -4528,137 +4596,139 @@ Node: Unfolding37244
Ref: -iterate37485 Ref: -iterate37485
Ref: -unfold37932 Ref: -unfold37932
Node: Predicates38737 Node: Predicates38737
Ref: -any?38914 Ref: -some38914
Ref: -all?39234 Ref: -every39331
Ref: -none?39564 Ref: -any?40010
Ref: -only-some?39866 Ref: -all?40341
Ref: -contains?40351 Ref: -none?41048
Ref: -same-items?40740 Ref: -only-some?41350
Ref: -is-prefix?41125 Ref: -contains?41835
Ref: -is-suffix?41451 Ref: -same-items?42224
Ref: -is-infix?41777 Ref: -is-prefix?42609
Ref: -cons-pair?42131 Ref: -is-suffix?42935
Node: Partitioning42456 Ref: -is-infix?43261
Ref: -split-at42644 Ref: -cons-pair?43615
Ref: -split-with43308 Node: Partitioning43940
Ref: -split-on43708 Ref: -split-at44128
Ref: -split-when44381 Ref: -split-with44792
Ref: -separate45018 Ref: -split-on45192
Ref: -partition45457 Ref: -split-when45863
Ref: -partition-all45906 Ref: -separate46500
Ref: -partition-in-steps46331 Ref: -partition46939
Ref: -partition-all-in-steps46825 Ref: -partition-all47388
Ref: -partition-by47307 Ref: -partition-in-steps47813
Ref: -partition-by-header47685 Ref: -partition-all-in-steps48307
Ref: -partition-after-pred48286 Ref: -partition-by48789
Ref: -partition-before-pred48733 Ref: -partition-by-header49167
Ref: -partition-before-item49118 Ref: -partition-after-pred49768
Ref: -partition-after-item49425 Ref: -partition-before-pred50215
Ref: -group-by49727 Ref: -partition-before-item50600
Node: Indexing50160 Ref: -partition-after-item50907
Ref: -elem-index50362 Ref: -group-by51209
Ref: -elem-indices50757 Node: Indexing51642
Ref: -find-index51137 Ref: -elem-index51844
Ref: -find-last-index51626 Ref: -elem-indices52239
Ref: -find-indices52130 Ref: -find-index52619
Ref: -grade-up52535 Ref: -find-last-index53108
Ref: -grade-down52942 Ref: -find-indices53612
Node: Set operations53356 Ref: -grade-up54017
Ref: -union53539 Ref: -grade-down54424
Ref: -difference53977 Node: Set operations54838
Ref: -intersection54389 Ref: -union55021
Ref: -powerset54821 Ref: -difference55459
Ref: -permutations55031 Ref: -intersection55871
Ref: -distinct55327 Ref: -powerset56303
Node: Other list operations55701 Ref: -permutations56513
Ref: -rotate55926 Ref: -distinct56809
Ref: -repeat56293 Node: Other list operations57183
Ref: -cons*56572 Ref: -rotate57408
Ref: -snoc56988 Ref: -repeat57761
Ref: -interpose57398 Ref: -cons*58040
Ref: -interleave57692 Ref: -snoc58456
Ref: -iota58058 Ref: -interpose58866
Ref: -zip-with58541 Ref: -interleave59160
Ref: -zip59255 Ref: -iota59526
Ref: -zip-lists60084 Ref: -zip-with60009
Ref: -zip-fill60782 Ref: -zip60723
Ref: -unzip61104 Ref: -zip-lists61552
Ref: -cycle61846 Ref: -zip-fill62250
Ref: -pad62245 Ref: -unzip62572
Ref: -table62564 Ref: -cycle63314
Ref: -table-flat63350 Ref: -pad63713
Ref: -first64355 Ref: -table64032
Ref: -some64841 Ref: -table-flat64818
Ref: -last65325 Ref: -first65823
Ref: -first-item65659 Ref: -last66309
Ref: -second-item66058 Ref: -first-item66643
Ref: -third-item66322 Ref: -second-item67042
Ref: -fourth-item66584 Ref: -third-item67306
Ref: -fifth-item66850 Ref: -fourth-item67568
Ref: -last-item67112 Ref: -fifth-item67834
Ref: -butlast67403 Ref: -last-item68096
Ref: -sort67648 Ref: -butlast68387
Ref: -list68134 Ref: -sort68632
Ref: -fix68703 Ref: -list69118
Node: Tree operations69192 Ref: -fix69687
Ref: -tree-seq69388 Node: Tree operations70176
Ref: -tree-map70243 Ref: -tree-seq70372
Ref: -tree-map-nodes70683 Ref: -tree-map71227
Ref: -tree-reduce71530 Ref: -tree-map-nodes71667
Ref: -tree-reduce-from72412 Ref: -tree-reduce72514
Ref: -tree-mapreduce73012 Ref: -tree-reduce-from73396
Ref: -tree-mapreduce-from73871 Ref: -tree-mapreduce73996
Ref: -clone75156 Ref: -tree-mapreduce-from74855
Node: Threading macros75483 Ref: -clone76140
Ref: ->75708 Node: Threading macros76467
Ref: ->>76196 Ref: ->76692
Ref: -->76699 Ref: ->>77180
Ref: -as->77255 Ref: -->77683
Ref: -some->77709 Ref: -as->78239
Ref: -some->>78082 Ref: -some->78693
Ref: -some-->78517 Ref: -some->>79066
Ref: -doto79066 Ref: -some-->79501
Node: Binding79619 Ref: -doto80050
Ref: -when-let79826 Node: Binding80603
Ref: -when-let*80281 Ref: -when-let80810
Ref: -if-let80804 Ref: -when-let*81265
Ref: -if-let*81164 Ref: -if-let81788
Ref: -let81781 Ref: -if-let*82148
Ref: -let*87853 Ref: -let82765
Ref: -lambda88790 Ref: -let*88837
Ref: -setq89596 Ref: -lambda89774
Node: Side effects90397 Ref: -setq90580
Ref: -each90591 Node: Side effects91381
Ref: -each-while91112 Ref: -each91575
Ref: -each-indexed91714 Ref: -each-while92096
Ref: -each-r92300 Ref: -each-indexed92698
Ref: -each-r-while92736 Ref: -each-r93284
Ref: -dotimes93362 Ref: -each-r-while93720
Node: Destructive operations93915 Ref: -dotimes94346
Ref: !cons94133 Node: Destructive operations94899
Ref: !cdr94337 Ref: !cons95117
Node: Function combinators94530 Ref: !cdr95321
Ref: -partial94734 Node: Function combinators95514
Ref: -rpartial95252 Ref: -partial95718
Ref: -juxt95900 Ref: -rpartial96236
Ref: -compose96352 Ref: -juxt96884
Ref: -applify96959 Ref: -compose97336
Ref: -on97389 Ref: -applify97943
Ref: -flip97913 Ref: -on98373
Ref: -const98224 Ref: -flip99145
Ref: -cut98562 Ref: -rotate-args99669
Ref: -not99042 Ref: -const100298
Ref: -orfn99351 Ref: -cut100640
Ref: -andfn99784 Ref: -not101120
Ref: -iteratefn100278 Ref: -orfn101646
Ref: -fixfn100980 Ref: -andfn102408
Ref: -prodfn102536 Ref: -iteratefn103164
Node: Development103594 Ref: -fixfn103866
Node: Contribute103883 Ref: -prodfn105422
Node: Contributors104895 Node: Development106480
Node: FDL106988 Node: Contribute106769
Node: GPL132308 Node: Contributors107781
Node: Index170057 Node: FDL109874
Node: GPL135194
Node: Index172943
 
End Tag Table End Tag Table