Browse Source

Update dash

master
Daniel 2 months ago
parent
commit
cf86962d6f
No known key found for this signature in database

elpa/dash-20210116.1426/dash-autoloads.el → elpa/dash-20210330.1544/dash-autoloads.el View File

@@ -57,7 +57,7 @@ See `dash-fontify-mode' for more information on Dash-Fontify mode.
57 57
 Register the Dash Info manual with `info-lookup-symbol'.
58 58
 This allows Dash symbols to be looked up with \\[info-lookup-symbol]." t nil)
59 59
 
60
-(if (fboundp 'register-definition-prefixes) (register-definition-prefixes "dash" '("!cdr" "!cons" "--" "->" "-a" "-butlast" "-c" "-d" "-e" "-f" "-gr" "-i" "-keep" "-l" "-m" "-non" "-only-some" "-p" "-r" "-s" "-t" "-u" "-value-to-list" "-when-let" "-zip" "dash-")))
60
+(if (fboundp 'register-definition-prefixes) (register-definition-prefixes "dash" '("!cdr" "!cons" "--" "->" "-a" "-butlast" "-c" "-d" "-e" "-f" "-gr" "-i" "-juxt" "-keep" "-l" "-m" "-no" "-o" "-p" "-r" "-s" "-t" "-u" "-value-to-list" "-when-let" "-zip" "dash-")))
61 61
 
62 62
 ;;;***
63 63
 

elpa/dash-20210116.1426/dash-pkg.el → elpa/dash-20210330.1544/dash-pkg.el View File

@@ -1,6 +1,6 @@
1
-(define-package "dash" "20210116.1426" "A modern list library for Emacs"
1
+(define-package "dash" "20210330.1544" "A modern list library for Emacs"
2 2
   '((emacs "24"))
3
-  :commit "4fb9613314f4ea07b1f6965799bd4a044703accd" :authors
3
+  :commit "b9286a84975874b10493f1cb4ea051c501f51273" :authors
4 4
   '(("Magnar Sveen" . "magnars@gmail.com"))
5 5
   :maintainer
6 6
   '("Magnar Sveen" . "magnars@gmail.com")

elpa/dash-20210116.1426/dash.el → elpa/dash-20210330.1544/dash.el View File

@@ -3,7 +3,7 @@
3 3
 ;; Copyright (C) 2012-2021 Free Software Foundation, Inc.
4 4
 
5 5
 ;; Author: Magnar Sveen <magnars@gmail.com>
6
-;; Version: 2.17.0
6
+;; Version: 2.18.1
7 7
 ;; Package-Requires: ((emacs "24"))
8 8
 ;; Keywords: extensions, lisp
9 9
 ;; Homepage: https://github.com/magnars/dash.el
@@ -68,8 +68,11 @@ This is the anaphoric counterpart to `-each'."
68 68
 (defun -each (list fn)
69 69
   "Call FN on each element of LIST.
70 70
 Return nil; this function is intended for side effects.
71
-Its anaphoric counterpart is `--each'.  For access to the current
72
-element's index in LIST, see `-each-indexed'."
71
+
72
+Its anaphoric counterpart is `--each'.
73
+
74
+For access to the current element's index in LIST, see
75
+`-each-indexed'."
73 76
   (declare (indent 1))
74 77
   (ignore (mapc fn list)))
75 78
 
@@ -79,6 +82,7 @@ element's index in LIST, see `-each-indexed'."
79 82
   "Call FN on each index and element of LIST.
80 83
 For each ITEM at INDEX in LIST, call (funcall FN INDEX ITEM).
81 84
 Return nil; this function is intended for side effects.
85
+
82 86
 See also: `-map-indexed'."
83 87
   (declare (indent 1))
84 88
   (--each list (funcall fn it-index it)))
@@ -107,6 +111,7 @@ This is the anaphoric counterpart to `-each-while'."
107 111
 Once an ITEM is reached for which PRED returns nil, FN is no
108 112
 longer called.  Return nil; this function is intended for side
109 113
 effects.
114
+
110 115
 Its anaphoric counterpart is `--each-while'."
111 116
   (declare (indent 2))
112 117
   (--each-while list (funcall pred it) (funcall fn it)))
@@ -136,6 +141,7 @@ This is the anaphoric counterpart to `-each-r'."
136 141
 (defun -each-r (list fn)
137 142
   "Call FN on each element of LIST in reversed order.
138 143
 Return nil; this function is intended for side effects.
144
+
139 145
 Its anaphoric counterpart is `--each-r'."
140 146
   (--each-r list (funcall fn it)))
141 147
 
@@ -167,6 +173,7 @@ This is the anaphoric counterpart to `-each-r-while'."
167 173
 Once an ITEM is reached for which PRED returns nil, FN is no
168 174
 longer called.  Return nil; this function is intended for side
169 175
 effects.
176
+
170 177
 Its anaphoric counterpart is `--each-r-while'."
171 178
   (--each-r-while list (funcall pred it) (funcall fn it)))
172 179
 
@@ -192,19 +199,21 @@ This is the anaphoric counterpart to `-dotimes'."
192 199
 FN is called with a single argument on successive integers
193 200
 running from 0, inclusive, to NUM, exclusive.  FN is not called
194 201
 if NUM is less than 1.
202
+
195 203
 This function's anaphoric counterpart is `--dotimes'."
196 204
   (declare (indent 1))
197 205
   (--dotimes num (funcall fn it)))
198 206
 
199 207
 (defun -map (fn list)
200 208
   "Apply FN to each item in LIST and return the list of results.
209
+
201 210
 This function's anaphoric counterpart is `--map'."
202 211
   (mapcar fn list))
203 212
 
204 213
 (defmacro --map (form list)
205 214
   "Eval FORM for each item in LIST and return the list of results.
206 215
 Each element of LIST in turn is bound to `it' before evaluating
207
-BODY.
216
+FORM.
208 217
 This is the anaphoric counterpart to `-map'."
209 218
   (declare (debug (def-form form)))
210 219
   `(mapcar (lambda (it) (ignore it) ,form) ,list))
@@ -232,6 +241,7 @@ LIST, then applying FN to that result and the second element,
232 241
 etc.  If LIST is empty, return INIT without calling FN.
233 242
 
234 243
 This function's anaphoric counterpart is `--reduce-from'.
244
+
235 245
 For other folds, see also `-reduce' and `-reduce-r'."
236 246
   (--reduce-from (funcall fn acc it) init list))
237 247
 
@@ -247,7 +257,9 @@ This is the anaphoric counterpart to `-reduce'."
247 257
     `(let ((,lv ,list))
248 258
        (if ,lv
249 259
            (--reduce-from ,form (car ,lv) (cdr ,lv))
250
-         (let (acc it)
260
+         ;; Explicit nil binding pacifies lexical "variable left uninitialized"
261
+         ;; warning.  See issue #377 and upstream https://bugs.gnu.org/47080.
262
+         (let ((acc nil) (it nil))
251 263
            (ignore acc it)
252 264
            ,form)))))
253 265
 
@@ -260,6 +272,7 @@ If LIST is empty, return the result of calling FN with no
260 272
 arguments.
261 273
 
262 274
 This function's anaphoric counterpart is `--reduce'.
275
+
263 276
 For other folds, see also `-reduce-from' and `-reduce-r'."
264 277
   (if list
265 278
       (-reduce-from fn (car list) (cdr list))
@@ -290,6 +303,7 @@ is like replacing the conses in LIST with applications of FN, and
290 303
 its last link with INIT, and evaluating the resulting expression.
291 304
 
292 305
 This function's anaphoric counterpart is `--reduce-r-from'.
306
+
293 307
 For other folds, see also `-reduce-r' and `-reduce'."
294 308
   (--reduce-r-from (funcall fn it acc) init list))
295 309
 
@@ -318,6 +332,7 @@ like replacing the conses in LIST with applications of FN,
318 332
 ignoring its last link, and evaluating the resulting expression.
319 333
 
320 334
 This function's anaphoric counterpart is `--reduce-r'.
335
+
321 336
 For other folds, see also `-reduce-r-from' and `-reduce'."
322 337
   (if list
323 338
       (--reduce-r (funcall fn it acc) list)
@@ -340,7 +355,9 @@ This is the anaphoric counterpart to `-reductions-from'."
340 355
 That is, a list of the intermediate values of the accumulator
341 356
 when `-reduce-from' (which see) is called with the same
342 357
 arguments.
358
+
343 359
 This function's anaphoric counterpart is `--reductions-from'.
360
+
344 361
 For other folds, see also `-reductions' and `-reductions-r'."
345 362
   (--reductions-from (funcall fn acc it) init list))
346 363
 
@@ -362,7 +379,9 @@ This is the anaphoric counterpart to `-reductions'."
362 379
   "Return a list of FN's intermediate reductions across LIST.
363 380
 That is, a list of the intermediate values of the accumulator
364 381
 when `-reduce' (which see) is called with the same arguments.
382
+
365 383
 This function's anaphoric counterpart is `--reductions'.
384
+
366 385
 For other folds, see also `-reductions' and `-reductions-r'."
367 386
   (if list
368 387
       (--reductions-from (funcall fn acc it) (car list) (cdr list))
@@ -384,7 +403,9 @@ This is the anaphoric counterpart to `-reductions-r-from'."
384 403
 That is, a list of the intermediate values of the accumulator
385 404
 when `-reduce-r-from' (which see) is called with the same
386 405
 arguments.
406
+
387 407
 This function's anaphoric counterpart is `--reductions-r-from'.
408
+
388 409
 For other folds, see also `-reductions' and `-reductions-r'."
389 410
   (--reductions-r-from (funcall fn it acc) init list))
390 411
 
@@ -400,7 +421,9 @@ This is the anaphoric counterpart to `-reductions-r'."
400 421
            (--reduce-from (cons (let ((acc (car acc))) (ignore acc) ,form) acc)
401 422
                           (list (car ,lv))
402 423
                           (cdr ,lv))
403
-         (let (acc it)
424
+         ;; Explicit nil binding pacifies lexical "variable left uninitialized"
425
+         ;; warning.  See issue #377 and upstream https://bugs.gnu.org/47080.
426
+         (let ((acc nil) (it nil))
404 427
            (ignore acc it)
405 428
            (list ,form))))))
406 429
 
@@ -408,7 +431,9 @@ This is the anaphoric counterpart to `-reductions-r'."
408 431
   "Return a list of FN's intermediate reductions across reversed LIST.
409 432
 That is, a list of the intermediate values of the accumulator
410 433
 when `-reduce-r' (which see) is called with the same arguments.
434
+
411 435
 This function's anaphoric counterpart is `--reductions-r'.
436
+
412 437
 For other folds, see also `-reductions-r-from' and
413 438
 `-reductions'."
414 439
   (if list
@@ -429,8 +454,11 @@ For the opposite operation, see also `--remove'."
429 454
 
430 455
 (defun -filter (pred list)
431 456
   "Return a new list of the items in LIST for which PRED returns non-nil.
457
+
432 458
 Alias: `-select'.
433
-This function's anaphoric counterpart `--filter'.
459
+
460
+This function's anaphoric counterpart is `--filter'.
461
+
434 462
 For similar operations, see also `-keep' and `-remove'."
435 463
   (--filter (funcall pred it) list))
436 464
 
@@ -448,8 +476,11 @@ For the opposite operation, see also `--filter'."
448 476
 
449 477
 (defun -remove (pred list)
450 478
   "Return a new list of the items in LIST for which PRED returns nil.
479
+
451 480
 Alias: `-reject'.
452
-This function's anaphoric counterpart `--remove'.
481
+
482
+This function's anaphoric counterpart is `--remove'.
483
+
453 484
 For similar operations, see also `-keep' and `-filter'."
454 485
   (--remove (funcall pred it) list))
455 486
 
@@ -480,72 +511,95 @@ This is a non-destructive operation, but only the front of LIST
480 511
 leading up to the removed item is a copy; the rest is LIST's
481 512
 original tail.  If no item is removed, then the result is a
482 513
 complete copy.
514
+
483 515
 Alias: `-reject-first'.
516
+
484 517
 This function's anaphoric counterpart is `--remove-first'.
518
+
485 519
 See also `-map-first', `-remove-item', and `-remove-last'."
486 520
   (--remove-first (funcall pred it) list))
487 521
 
488 522
 (defalias '-reject-first '-remove-first)
489 523
 (defalias '--reject-first '--remove-first)
490 524
 
525
+(defmacro --remove-last (form list)
526
+  "Remove the last item from LIST for which FORM evals to non-nil.
527
+Each element of LIST in turn is bound to `it' before evaluating
528
+FORM.  The result is a copy of LIST regardless of whether an
529
+element is removed.
530
+This is the anaphoric counterpart to `-remove-last'."
531
+  (declare (debug (form form)))
532
+  `(nreverse (--remove-first ,form (reverse ,list))))
533
+
491 534
 (defun -remove-last (pred list)
492
-  "Return a new list with the last item matching PRED removed.
535
+  "Remove the last item from LIST for which PRED returns non-nil.
536
+The result is a copy of LIST regardless of whether an element is
537
+removed.
493 538
 
494
-Alias: `-reject-last'
539
+Alias: `-reject-last'.
495 540
 
496
-See also: `-remove', `-map-last'"
497
-  (nreverse (-remove-first pred (reverse list))))
541
+This function's anaphoric counterpart is `--remove-last'.
498 542
 
499
-(defmacro --remove-last (form list)
500
-  "Anaphoric form of `-remove-last'."
501
-  (declare (debug (form form)))
502
-  `(-remove-last (lambda (it) ,form) ,list))
543
+See also `-map-last', `-remove-item', and `-remove-first'."
544
+  (--remove-last (funcall pred it) list))
503 545
 
504 546
 (defalias '-reject-last '-remove-last)
505 547
 (defalias '--reject-last '--remove-last)
506 548
 
507
-(defun -remove-item (item list)
508
-  "Remove all occurrences of ITEM from LIST.
509
-
510
-Comparison is done with `equal'."
511
-  (declare (pure t) (side-effect-free t))
512
-  (--remove (equal it item) list))
549
+(defalias '-remove-item #'remove
550
+  "Return a copy of LIST with all occurrences of ITEM removed.
551
+The comparison is done with `equal'.
552
+\n(fn ITEM LIST)")
513 553
 
514 554
 (defmacro --keep (form list)
515
-  "Anaphoric form of `-keep'."
555
+  "Eval FORM for each item in LIST and return the non-nil results.
556
+Like `--filter', but returns the non-nil results of FORM instead
557
+of the corresponding elements of LIST.  Each element of LIST in
558
+turn is bound to `it' and its index within LIST to `it-index'
559
+before evaluating FORM.
560
+This is the anaphoric counterpart to `-keep'."
516 561
   (declare (debug (form form)))
517 562
   (let ((r (make-symbol "result"))
518 563
         (m (make-symbol "mapped")))
519 564
     `(let (,r)
520
-       (--each ,list (let ((,m ,form)) (when ,m (!cons ,m ,r))))
565
+       (--each ,list (let ((,m ,form)) (when ,m (push ,m ,r))))
521 566
        (nreverse ,r))))
522 567
 
523 568
 (defun -keep (fn list)
524
-  "Return a new list of the non-nil results of applying FN to the items in LIST.
569
+  "Return a new list of the non-nil results of applying FN to each item in LIST.
570
+Like `-filter', but returns the non-nil results of FN instead of
571
+the corresponding elements of LIST.
525 572
 
526
-If you want to select the original items satisfying a predicate use `-filter'."
573
+Its anaphoric counterpart is `--keep'."
527 574
   (--keep (funcall fn it) list))
528 575
 
529 576
 (defun -non-nil (list)
530
-  "Return all non-nil elements of LIST."
577
+  "Return a copy of LIST with all nil items removed."
531 578
   (declare (pure t) (side-effect-free t))
532
-  (-remove 'null list))
579
+  (--filter it list))
533 580
 
534 581
 (defmacro --map-indexed (form list)
535
-  "Anaphoric form of `-map-indexed'."
582
+  "Eval FORM for each item in LIST and return the list of results.
583
+Each element of LIST in turn is bound to `it' and its index
584
+within LIST to `it-index' before evaluating FORM.  This is like
585
+`--map', but additionally makes `it-index' available to FORM.
586
+
587
+This is the anaphoric counterpart to `-map-indexed'."
536 588
   (declare (debug (form form)))
537 589
   (let ((r (make-symbol "result")))
538 590
     `(let (,r)
539 591
        (--each ,list
540
-         (!cons ,form ,r))
592
+         (push ,form ,r))
541 593
        (nreverse ,r))))
542 594
 
543 595
 (defun -map-indexed (fn list)
544
-  "Return a new list consisting of the result of (FN index item) for each item in LIST.
596
+  "Apply FN to each index and item in LIST and return the list of results.
597
+This is like `-map', but FN takes two arguments: the index of the
598
+current element within LIST, and the element itself.
545 599
 
546
-In the anaphoric form `--map-indexed', the index is exposed as symbol `it-index'.
600
+This function's anaphoric counterpart is `--map-indexed'.
547 601
 
548
-See also: `-each-indexed'."
602
+For a side-effecting variant, see also `-each-indexed'."
549 603
   (--map-indexed (funcall fn it-index it) list))
550 604
 
551 605
 (defmacro --map-when (pred rep list)
@@ -635,12 +689,15 @@ Thus function FN should return a list."
635 689
 (defmacro --iterate (form init n)
636 690
   "Anaphoric version of `-iterate'."
637 691
   (declare (debug (form form form)))
638
-  (let ((res (make-symbol "result")))
639
-    `(let ((it ,init) ,res)
640
-       (dotimes (_ ,n)
641
-         (push it ,res)
642
-         (setq it ,form))
643
-       (nreverse ,res))))
692
+  (let ((res (make-symbol "result"))
693
+        (len (make-symbol "n")))
694
+    `(let ((,len ,n))
695
+       (when (> ,len 0)
696
+         (let* ((it ,init)
697
+                (,res (list it)))
698
+           (dotimes (_ (1- ,len))
699
+             (push (setq it ,form) ,res))
700
+           (nreverse ,res))))))
644 701
 
645 702
 (defun -iterate (fun init n)
646 703
   "Return a list of iterated applications of FUN to INIT.
@@ -674,7 +731,9 @@ See also: `-flatten-n'"
674 731
 
675 732
 See also: `-flatten'"
676 733
   (declare (pure t) (side-effect-free t))
677
-  (-last-item (--iterate (--mapcat (-list it) it) list (1+ num))))
734
+  (dotimes (_ num)
735
+    (setq list (apply #'append (mapcar #'-list list))))
736
+  list)
678 737
 
679 738
 (defun -concat (&rest lists)
680 739
   "Return a new list with the concatenation of the elements in the supplied LISTS."
@@ -757,7 +816,9 @@ This is the anaphoric counterpart to `-first'."
757 816
   "Return the first item in LIST for which PRED returns non-nil.
758 817
 Return nil if no such element is found.
759 818
 To get the first item in the list no questions asked, use `car'.
819
+
760 820
 Alias: `-find'.
821
+
761 822
 This function's anaphoric counterpart is `--first'."
762 823
   (--first (funcall pred it) list))
763 824
 
@@ -778,7 +839,9 @@ This is the anaphoric counterpart to `-some'."
778 839
 
779 840
 (defun -some (pred list)
780 841
   "Return (PRED x) for the first LIST item where (PRED x) is non-nil, else nil.
842
+
781 843
 Alias: `-any'.
844
+
782 845
 This function's anaphoric counterpart is `--some'."
783 846
   (--some (funcall pred it) list))
784 847
 
@@ -995,7 +1058,9 @@ This is the anaphoric counterpart to `-take-while'."
995 1058
 PRED is a function of one argument.  Return a new list of the
996 1059
 successive elements from the start of LIST for which PRED returns
997 1060
 non-nil.
1061
+
998 1062
 This function's anaphoric counterpart is `--take-while'.
1063
+
999 1064
 For another variant, see also `-drop-while'."
1000 1065
   (--take-while (funcall pred it) list))
1001 1066
 
@@ -1017,7 +1082,9 @@ This is the anaphoric counterpart to `-drop-while'."
1017 1082
 PRED is a function of one argument.  Return the tail (not a copy)
1018 1083
 of LIST starting from its first element for which PRED returns
1019 1084
 nil.
1085
+
1020 1086
 This function's anaphoric counterpart is `--drop-while'.
1087
+
1021 1088
 For another variant, see also `-take-while'."
1022 1089
   (--drop-while (funcall pred it) list))
1023 1090
 
@@ -1043,6 +1110,7 @@ See also: `-take'."
1043 1110
   "Return the tail (not a copy) of LIST without the first N items.
1044 1111
 Return nil if LIST contains N items or fewer.
1045 1112
 Return LIST if N is zero or less.
1113
+
1046 1114
 For another variant, see also `-drop-last'.
1047 1115
 \n(fn N LIST)")
1048 1116
 
@@ -1574,13 +1642,6 @@ See also: `-flatten-n', `-table'"
1574 1642
         (dash--table-carry lists restore-lists)))
1575 1643
     (nreverse re)))
1576 1644
 
1577
-(defun -partial (fn &rest args)
1578
-  "Take a function FN and fewer than the normal arguments to FN,
1579
-and return a fn that takes a variable number of additional ARGS.
1580
-When called, the returned function calls FN with ARGS first and
1581
-then additional args."
1582
-  (apply 'apply-partially fn args))
1583
-
1584 1645
 (defun -elem-index (elem list)
1585 1646
   "Return the index of the first element in the given LIST which
1586 1647
 is equal to the query element ELEM, or nil if there is no
@@ -1668,7 +1729,8 @@ See also: `-select-columns', `-select-by-indices'"
1668 1729
 in the first form, making a list of it if it is not a list
1669 1730
 already. If there are more forms, insert the first form as the
1670 1731
 second item in second form, etc."
1671
-  (declare (debug (form &rest [&or symbolp (sexp &rest form)])))
1732
+  (declare (debug (form &rest [&or symbolp (sexp &rest form)]))
1733
+           (indent 1))
1672 1734
   (cond
1673 1735
    ((null form) x)
1674 1736
    ((null more) (if (listp form)
@@ -1681,7 +1743,8 @@ second item in second form, etc."
1681 1743
 in the first form, making a list of it if it is not a list
1682 1744
 already. If there are more forms, insert the first form as the
1683 1745
 last item in second form, etc."
1684
-  (declare (debug ->))
1746
+  (declare (debug ->)
1747
+           (indent 1))
1685 1748
   (cond
1686 1749
    ((null form) x)
1687 1750
    ((null more) (if (listp form)
@@ -1735,23 +1798,24 @@ and when that result is non-nil, through the next form, etc."
1735 1798
                    (->> ,result ,form))
1736 1799
                  ,@more))))
1737 1800
 
1738
-(defmacro -some--> (x &optional form &rest more)
1739
-  "When expr is non-nil, thread it through the first form (via `-->'),
1740
-and when that result is non-nil, through the next form, etc."
1741
-  (declare (debug ->)
1742
-           (indent 1))
1743
-  (if (null form) x
1801
+(defmacro -some--> (expr &rest forms)
1802
+  "Thread EXPR through FORMS via `-->', while the result is non-nil.
1803
+When EXPR evaluates to non-nil, thread the result through the
1804
+first of FORMS, and when that result is non-nil, thread it
1805
+through the next form, etc."
1806
+  (declare (debug (form &rest &or symbolp consp)) (indent 1))
1807
+  (if (null forms) expr
1744 1808
     (let ((result (make-symbol "result")))
1745
-      `(-some--> (-when-let (,result ,x)
1746
-                   (--> ,result ,form))
1747
-                 ,@more))))
1809
+      `(-some--> (-when-let (,result ,expr)
1810
+                   (--> ,result ,(car forms)))
1811
+         ,@(cdr forms)))))
1748 1812
 
1749 1813
 (defmacro -doto (init &rest forms)
1750 1814
   "Evaluate INIT and pass it as argument to FORMS with `->'.
1751 1815
 The RESULT of evaluating INIT is threaded through each of FORMS
1752 1816
 individually using `->', which see.  The return value is RESULT,
1753 1817
 which FORMS may have modified by side effect."
1754
-  (declare (debug (form body)) (indent 1))
1818
+  (declare (debug (form &rest &or symbolp consp)) (indent 1))
1755 1819
   (let ((retval (make-symbol "result")))
1756 1820
     `(let ((,retval ,init))
1757 1821
        ,@(mapcar (lambda (form) `(-> ,retval ,form)) forms)
@@ -2588,20 +2652,22 @@ Alias: `-same-items-p'"
2588 2652
 (defalias '-same-items-p '-same-items?)
2589 2653
 
2590 2654
 (defun -is-prefix? (prefix list)
2591
-  "Return non-nil if PREFIX is prefix of LIST.
2655
+  "Return non-nil if PREFIX is a prefix of LIST.
2592 2656
 
2593
-Alias: `-is-prefix-p'"
2657
+Alias: `-is-prefix-p'."
2594 2658
   (declare (pure t) (side-effect-free t))
2595
-  (--each-while list (equal (car prefix) it)
2596
-    (!cdr prefix))
2597
-  (not prefix))
2659
+  (--each-while list (and (equal (car prefix) it)
2660
+                          (!cdr prefix)))
2661
+  (null prefix))
2598 2662
 
2599 2663
 (defun -is-suffix? (suffix list)
2600
-  "Return non-nil if SUFFIX is suffix of LIST.
2664
+  "Return non-nil if SUFFIX is a suffix of LIST.
2601 2665
 
2602
-Alias: `-is-suffix-p'"
2666
+Alias: `-is-suffix-p'."
2603 2667
   (declare (pure t) (side-effect-free t))
2604
-  (-is-prefix? (reverse suffix) (reverse list)))
2668
+  (cond ((null suffix))
2669
+        ((setq list (member (car suffix) list))
2670
+         (equal (cdr suffix) (cdr list)))))
2605 2671
 
2606 2672
 (defun -is-infix? (infix list)
2607 2673
   "Return non-nil if INFIX is infix of LIST.
@@ -2768,6 +2834,7 @@ the new seed."
2768 2834
 (defun -cons-pair? (obj)
2769 2835
   "Return non-nil if OBJ is a true cons pair.
2770 2836
 That is, a cons (A . B) where B is not a list.
2837
+
2771 2838
 Alias: `-cons-pair-p'."
2772 2839
   (declare (pure t) (side-effect-free t))
2773 2840
   (nlistp (cdr-safe obj)))
@@ -2934,20 +3001,214 @@ structure such as plist or alist."
2934 3001
   (declare (pure t) (side-effect-free t))
2935 3002
   (-tree-map 'identity list))
2936 3003
 
3004
+;;; Combinators
3005
+
3006
+(defalias '-partial #'apply-partially)
3007
+
3008
+(defun -rpartial (fn &rest args)
3009
+  "Return a function that is a partial application of FN to ARGS.
3010
+ARGS is a list of the last N arguments to pass to FN.  The result
3011
+is a new function which does the same as FN, except that the last
3012
+N arguments are fixed at the values with which this function was
3013
+called.  This is like `-partial', except the arguments are fixed
3014
+starting from the right rather than the left."
3015
+  (declare (pure t) (side-effect-free t))
3016
+  (lambda (&rest args-before) (apply fn (append args-before args))))
3017
+
3018
+(defun -juxt (&rest fns)
3019
+  "Return a function that is the juxtaposition of FNS.
3020
+The returned function takes a variable number of ARGS, applies
3021
+each of FNS in turn to ARGS, and returns the list of results."
3022
+  (declare (pure t) (side-effect-free t))
3023
+  (lambda (&rest args) (mapcar (lambda (x) (apply x args)) fns)))
3024
+
3025
+(defun -compose (&rest fns)
3026
+  "Compose FNS into a single composite function.
3027
+Return a function that takes a variable number of ARGS, applies
3028
+the last function in FNS to ARGS, and returns the result of
3029
+calling each remaining function on the result of the previous
3030
+function, right-to-left.  If no FNS are given, return a variadic
3031
+`identity' function."
3032
+  (declare (pure t) (side-effect-free t))
3033
+  (let* ((fns (nreverse fns))
3034
+         (head (car fns))
3035
+         (tail (cdr fns)))
3036
+    (cond (tail
3037
+           (lambda (&rest args)
3038
+             (--reduce-from (funcall it acc) (apply head args) tail)))
3039
+          (fns head)
3040
+          ((lambda (&optional arg &rest _) arg)))))
3041
+
3042
+(defun -applify (fn)
3043
+  "Return a function that applies FN to a single list of args.
3044
+This changes the arity of FN from taking N distinct arguments to
3045
+taking 1 argument which is a list of N arguments."
3046
+  (declare (pure t) (side-effect-free t))
3047
+  (lambda (args) (apply fn args)))
3048
+
3049
+(defun -on (operator transformer)
3050
+  "Return a function of two arguments that first applies
3051
+TRANSFORMER to each of them and then applies OPERATOR on the
3052
+results (in the same order).
3053
+
3054
+In types: (b -> b -> c) -> (a -> b) -> a -> a -> c"
3055
+  (lambda (x y) (funcall operator (funcall transformer x) (funcall transformer y))))
3056
+
3057
+(defun -flip (func)
3058
+  "Swap the order of arguments for binary function FUNC.
3059
+
3060
+In types: (a -> b -> c) -> b -> a -> c"
3061
+  (lambda (x y) (funcall func y x)))
3062
+
3063
+(defun -const (c)
3064
+  "Return a function that returns C ignoring any additional arguments.
3065
+
3066
+In types: a -> b -> a"
3067
+  (lambda (&rest _) c))
3068
+
3069
+(defmacro -cut (&rest params)
3070
+  "Take n-ary function and n arguments and specialize some of them.
3071
+Arguments denoted by <> will be left unspecialized.
3072
+
3073
+See SRFI-26 for detailed description."
3074
+  (let* ((i 0)
3075
+         (args (--keep (when (eq it '<>)
3076
+                         (setq i (1+ i))
3077
+                         (make-symbol (format "D%d" i)))
3078
+                       params)))
3079
+    `(lambda ,args
3080
+       ,(let ((body (--map (if (eq it '<>) (pop args) it) params)))
3081
+          (if (eq (car params) '<>)
3082
+              (cons 'funcall body)
3083
+            body)))))
3084
+
3085
+(defun -not (pred)
3086
+  "Take a unary predicate PRED and return a unary predicate
3087
+that returns t if PRED returns nil and nil if PRED returns
3088
+non-nil."
3089
+  (lambda (x) (not (funcall pred x))))
3090
+
3091
+(defun -orfn (&rest preds)
3092
+  "Take list of unary predicates PREDS and return a unary
3093
+predicate with argument x that returns non-nil if at least one of
3094
+the PREDS returns non-nil on x.
3095
+
3096
+In types: [a -> Bool] -> a -> Bool"
3097
+  (lambda (x) (-any? (-cut funcall <> x) preds)))
3098
+
3099
+(defun -andfn (&rest preds)
3100
+  "Take list of unary predicates PREDS and return a unary
3101
+predicate with argument x that returns non-nil if all of the
3102
+PREDS returns non-nil on x.
3103
+
3104
+In types: [a -> Bool] -> a -> Bool"
3105
+  (lambda (x) (-all? (-cut funcall <> x) preds)))
3106
+
3107
+(defun -iteratefn (fn n)
3108
+  "Return a function FN composed N times with itself.
3109
+
3110
+FN is a unary function.  If you need to use a function of higher
3111
+arity, use `-applify' first to turn it into a unary function.
3112
+
3113
+With n = 0, this acts as identity function.
3114
+
3115
+In types: (a -> a) -> Int -> a -> a.
3116
+
3117
+This function satisfies the following law:
3118
+
3119
+  (funcall (-iteratefn fn n) init) = (-last-item (-iterate fn init (1+ n)))."
3120
+  (lambda (x) (--dotimes n (setq x (funcall fn x))) x))
3121
+
3122
+(defun -counter (&optional beg end inc)
3123
+  "Return a closure that counts from BEG to END, with increment INC.
3124
+
3125
+The closure will return the next value in the counting sequence
3126
+each time it is called, and nil after END is reached. BEG
3127
+defaults to 0, INC defaults to 1, and if END is nil, the counter
3128
+will increment indefinitely.
3129
+
3130
+The closure accepts any number of arguments, which are discarded."
3131
+  (let ((inc (or inc 1))
3132
+        (n (or beg 0)))
3133
+    (lambda (&rest _)
3134
+      (when (or (not end) (< n end))
3135
+        (prog1 n
3136
+          (setq n (+ n inc)))))))
3137
+
3138
+(defvar -fixfn-max-iterations 1000
3139
+  "The default maximum number of iterations performed by `-fixfn'
3140
+  unless otherwise specified.")
3141
+
3142
+(defun -fixfn (fn &optional equal-test halt-test)
3143
+  "Return a function that computes the (least) fixpoint of FN.
3144
+
3145
+FN must be a unary function. The returned lambda takes a single
3146
+argument, X, the initial value for the fixpoint iteration. The
3147
+iteration halts when either of the following conditions is satisfied:
3148
+
3149
+ 1. Iteration converges to the fixpoint, with equality being
3150
+    tested using EQUAL-TEST. If EQUAL-TEST is not specified,
3151
+    `equal' is used. For functions over the floating point
3152
+    numbers, it may be necessary to provide an appropriate
3153
+    approximate comparison test.
3154
+
3155
+ 2. HALT-TEST returns a non-nil value. HALT-TEST defaults to a
3156
+    simple counter that returns t after `-fixfn-max-iterations',
3157
+    to guard against infinite iteration. Otherwise, HALT-TEST
3158
+    must be a function that accepts a single argument, the
3159
+    current value of X, and returns non-nil as long as iteration
3160
+    should continue. In this way, a more sophisticated
3161
+    convergence test may be supplied by the caller.
3162
+
3163
+The return value of the lambda is either the fixpoint or, if
3164
+iteration halted before converging, a cons with car `halted' and
3165
+cdr the final output from HALT-TEST.
3166
+
3167
+In types: (a -> a) -> a -> a."
3168
+  (let ((eqfn   (or equal-test 'equal))
3169
+    (haltfn (or halt-test
3170
+            (-not
3171
+              (-counter 0 -fixfn-max-iterations)))))
3172
+    (lambda (x)
3173
+      (let ((re (funcall fn x))
3174
+        (halt? (funcall haltfn x)))
3175
+    (while (and (not halt?) (not (funcall eqfn x re)))
3176
+      (setq x     re
3177
+        re    (funcall fn re)
3178
+        halt? (funcall haltfn re)))
3179
+    (if halt? (cons 'halted halt?)
3180
+      re)))))
3181
+
3182
+(defun -prodfn (&rest fns)
3183
+  "Take a list of n functions and return a function that takes a
3184
+list of length n, applying i-th function to i-th element of the
3185
+input list.  Returns a list of length n.
3186
+
3187
+In types (for n=2): ((a -> b), (c -> d)) -> (a, c) -> (b, d)
3188
+
3189
+This function satisfies the following laws:
3190
+
3191
+  (-compose (-prodfn f g ...) (-prodfn f\\=' g\\=' ...)) = (-prodfn (-compose f f\\=') (-compose g g\\=') ...)
3192
+  (-prodfn f g ...) = (-juxt (-compose f (-partial \\='nth 0)) (-compose g (-partial \\='nth 1)) ...)
3193
+  (-compose (-prodfn f g ...) (-juxt f\\=' g\\=' ...)) = (-juxt (-compose f f\\=') (-compose g g\\=') ...)
3194
+  (-compose (-partial \\='nth n) (-prod f1 f2 ...)) = (-compose fn (-partial \\='nth n))"
3195
+  (lambda (x) (-zip-with 'funcall fns x)))
3196
+
2937 3197
 ;;; Font lock
2938 3198
 
2939 3199
 (defvar dash--keywords
2940 3200
   `(;; TODO: Do not fontify the following automatic variables
2941 3201
     ;; globally; detect and limit to their local anaphoric scope.
2942
-    (,(concat "\\_<" (regexp-opt '("acc" "it" "it-index" "other")) "\\_>")
3202
+    (,(rx symbol-start (| "acc" "it" "it-index" "other") symbol-end)
2943 3203
      0 font-lock-variable-name-face)
2944 3204
     ;; Macros in dev/examples.el.  Based on `lisp-mode-symbol-regexp'.
2945
-    (,(concat "(" (regexp-opt '("defexamples" "def-example-group") t)
2946
-              "\\_>[\t ]+\\(\\(?:\\sw\\|\\s_\\|\\\\.\\)*\\)")
3205
+    (,(rx ?\( (group (| "defexamples" "def-example-group")) symbol-end
3206
+          (+ (in "\t "))
3207
+          (group (* (| (syntax word) (syntax symbol) (: ?\\ nonl)))))
2947 3208
      (1 font-lock-keyword-face)
2948 3209
      (2 font-lock-function-name-face))
2949 3210
     ;; Symbols in dev/examples.el.
2950
-    ,(concat "\\_<" (regexp-opt '("=>" "~>" "!!>")) "\\_>")
3211
+    ,(rx symbol-start (| "=>" "~>" "!!>") symbol-end)
2951 3212
     ;; Elisp macro fontification was static prior to Emacs 25.
2952 3213
     ,@(when (< emacs-major-version 25)
2953 3214
         (let ((macs '("!cdr"

elpa/dash-20210330.1544/dash.info
File diff suppressed because it is too large
View File


elpa/dash-20210116.1426/dir → elpa/dash-20210330.1544/dir View File


Loading…
Cancel
Save