branch: externals/dash commit 72b8d39458fc57a7d033724c727677e8d2cc0a52 Author: Basil L. Contovounesios <conto...@tcd.ie> Commit: Basil L. Contovounesios <conto...@tcd.ie>
Add -common-prefix Re: #260 --- README.md | 12 +++ dash.el | 10 ++ dash.info | 284 ++++++++++++++++++++++++++++------------------------- dash.texi | 20 ++++ dev/examples.el | 9 ++ readme-template.md | 1 + 6 files changed, 200 insertions(+), 136 deletions(-) diff --git a/README.md b/README.md index 8f18045..a683c4d 100644 --- a/README.md +++ b/README.md @@ -146,6 +146,7 @@ Functions reducing lists into single value. * [-running-product](#-running-product-list) `(list)` * [-inits](#-inits-list) `(list)` * [-tails](#-tails-list) `(list)` +* [-common-prefix](#-common-prefix-rest-lists) `(&rest lists)` * [-min](#-min-list) `(list)` * [-min-by](#-min-by-comparator-list) `(comparator list)` * [-max](#-max-list) `(list)` @@ -1043,6 +1044,16 @@ Return all suffixes of `list` (-tails '(1)) ;; => '((1) nil) ``` +#### -common-prefix `(&rest lists)` + +Return the longest common prefix of `lists`. + +```el +(-common-prefix '(1)) ;; => '(1) +(-common-prefix '(1 2) nil '(1 2)) ;; => nil +(-common-prefix '(1 2) '(1 2 3) '(1 2 3 4)) ;; => '(1 2) +``` + #### -min `(list)` Return the smallest value from `list` of numbers or markers. @@ -2907,6 +2918,7 @@ Change `readme-template.md` or `examples-to-docs.el` instead. - [Vasilij Schneidermann](https://github.com/wasamasa) contributed `-some`. - [William West](https://github.com/occidens) made `-fixfn` more robust at handling floats. - [Cam Saül](https://github.com/camsaul) contributed `-some->`, `-some->>`, and `-some-->`. + - [Basil L. Contovounesios](https://github.com/basil-conto) contributed `-common-prefix`. Thanks! diff --git a/dash.el b/dash.el index 1fcd3e3..e8ff669 100644 --- a/dash.el +++ b/dash.el @@ -2115,6 +2115,15 @@ or with `-compare-fn' if that's non-nil." "Return all suffixes of LIST" (-reductions-r-from 'cons nil list)) +(defun -common-prefix (&rest lists) + "Return the longest common prefix of LISTS." + (declare (pure t) (side-effect-free t)) + (--reduce (let (head prefix) + (while (and acc it (equal (setq head (pop acc)) (pop it))) + (push head prefix)) + (nreverse prefix)) + lists)) + (defun -contains? (list element) "Return non-nil if LIST contains ELEMENT. @@ -2687,6 +2696,7 @@ structure such as plist or alist." "-permutations" "-inits" "-tails" + "-common-prefix" "-contains?" "-contains-p" "-same-items?" diff --git a/dash.info b/dash.info index 86cf80f..3116c4b 100644 --- a/dash.info +++ b/dash.info @@ -938,6 +938,16 @@ Functions reducing lists into single value. (-tails '(1)) ⇒ '((1) nil) + -- Function: -common-prefix (&rest lists) + Return the longest common prefix of LISTS. + + (-common-prefix '(1)) + ⇒ '(1) + (-common-prefix '(1 2) nil '(1 2)) + ⇒ nil + (-common-prefix '(1 2) '(1 2 3) '(1 2 3 4)) + ⇒ '(1 2) + -- Function: -min (list) Return the smallest value from LIST of numbers or markers. @@ -2871,6 +2881,7 @@ Index * -butlast: Other list operations. (line 311) * -clone: Tree operations. (line 123) +* -common-prefix: Reductions. (line 225) * -compose: Function combinators. (line 42) * -concat: List to list. (line 22) @@ -2953,10 +2964,10 @@ Index * -map-last: Maps. (line 52) * -map-when: Maps. (line 21) * -mapcat: Maps. (line 124) -* -max: Reductions. (line 249) -* -max-by: Reductions. (line 259) -* -min: Reductions. (line 225) -* -min-by: Reductions. (line 235) +* -max: Reductions. (line 259) +* -max-by: Reductions. (line 269) +* -min: Reductions. (line 235) +* -min-by: Reductions. (line 245) * -non-nil: Sublist selection. (line 80) * -none?: Predicates. (line 30) * -not: Function combinators. @@ -3131,138 +3142,139 @@ Ref: -product29402 Ref: -running-product29611 Ref: -inits29924 Ref: -tails30172 -Ref: -min30419 -Ref: -min-by30645 -Ref: -max31168 -Ref: -max-by31393 -Node: Unfolding31921 -Ref: -iterate32160 -Ref: -unfold32605 -Node: Predicates33413 -Ref: -any?33537 -Ref: -all?33857 -Ref: -none?34187 -Ref: -only-some?34489 -Ref: -contains?34974 -Ref: -same-items?35363 -Ref: -is-prefix?35748 -Ref: -is-suffix?36071 -Ref: -is-infix?36394 -Node: Partitioning36748 -Ref: -split-at36936 -Ref: -split-with37221 -Ref: -split-on37624 -Ref: -split-when38300 -Ref: -separate38940 -Ref: -partition39382 -Ref: -partition-all39834 -Ref: -partition-in-steps40262 -Ref: -partition-all-in-steps40759 -Ref: -partition-by41244 -Ref: -partition-by-header41626 -Ref: -partition-after-pred42230 -Ref: -partition-before-pred42601 -Ref: -partition-before-item42979 -Ref: -partition-after-item43290 -Ref: -group-by43596 -Node: Indexing44033 -Ref: -elem-index44235 -Ref: -elem-indices44630 -Ref: -find-index45013 -Ref: -find-last-index45502 -Ref: -find-indices46006 -Ref: -grade-up46414 -Ref: -grade-down46817 -Node: Set operations47227 -Ref: -union47410 -Ref: -difference47852 -Ref: -intersection48269 -Ref: -powerset48706 -Ref: -permutations48919 -Ref: -distinct49219 -Node: Other list operations49543 -Ref: -rotate49768 -Ref: -repeat50063 -Ref: -cons*50326 -Ref: -snoc50713 -Ref: -interpose51126 -Ref: -interleave51424 -Ref: -zip-with51793 -Ref: -zip52510 -Ref: -zip-fill53316 -Ref: -unzip53639 -Ref: -cycle54173 -Ref: -pad54546 -Ref: -table54869 -Ref: -table-flat55659 -Ref: -first56668 -Ref: -some57040 -Ref: -last57349 -Ref: -first-item57683 -Ref: -second-item58099 -Ref: -third-item58379 -Ref: -fourth-item58657 -Ref: -fifth-item58923 -Ref: -last-item59185 -Ref: -butlast59477 -Ref: -sort59724 -Ref: -list60212 -Ref: -fix60543 -Node: Tree operations61083 -Ref: -tree-seq61279 -Ref: -tree-map62137 -Ref: -tree-map-nodes62580 -Ref: -tree-reduce63435 -Ref: -tree-reduce-from64317 -Ref: -tree-mapreduce64918 -Ref: -tree-mapreduce-from65778 -Ref: -clone67064 -Node: Threading macros67392 -Ref: ->67537 -Ref: ->>68029 -Ref: -->68534 -Ref: -as->69095 -Ref: -some->69550 -Ref: -some->>69924 -Ref: -some-->70360 -Node: Binding70831 -Ref: -when-let71043 -Ref: -when-let*71528 -Ref: -if-let72056 -Ref: -if-let*72451 -Ref: -let73068 -Ref: -let*77861 -Ref: -lambda78802 -Node: Side-effects79604 -Ref: -each79798 -Ref: -each-while80205 -Ref: -each-indexed80565 -Ref: -dotimes81083 -Ref: -doto81386 -Node: Destructive operations81813 -Ref: !cons81986 -Ref: !cdr82192 -Node: Function combinators82387 -Ref: -partial82661 -Ref: -rpartial83056 -Ref: -juxt83458 -Ref: -compose83890 -Ref: -applify84448 -Ref: -on84895 -Ref: -flip85418 -Ref: -const85730 -Ref: -cut86074 -Ref: -not86560 -Ref: -orfn86870 -Ref: -andfn87304 -Ref: -iteratefn87799 -Ref: -fixfn88502 -Ref: -prodfn90071 -Node: Development91137 -Node: Contribute91486 -Node: Changes92234 -Node: Contributors95233 -Node: Index96857 +Ref: -common-prefix30419 +Ref: -min30713 +Ref: -min-by30939 +Ref: -max31462 +Ref: -max-by31687 +Node: Unfolding32215 +Ref: -iterate32454 +Ref: -unfold32899 +Node: Predicates33707 +Ref: -any?33831 +Ref: -all?34151 +Ref: -none?34481 +Ref: -only-some?34783 +Ref: -contains?35268 +Ref: -same-items?35657 +Ref: -is-prefix?36042 +Ref: -is-suffix?36365 +Ref: -is-infix?36688 +Node: Partitioning37042 +Ref: -split-at37230 +Ref: -split-with37515 +Ref: -split-on37918 +Ref: -split-when38594 +Ref: -separate39234 +Ref: -partition39676 +Ref: -partition-all40128 +Ref: -partition-in-steps40556 +Ref: -partition-all-in-steps41053 +Ref: -partition-by41538 +Ref: -partition-by-header41920 +Ref: -partition-after-pred42524 +Ref: -partition-before-pred42895 +Ref: -partition-before-item43273 +Ref: -partition-after-item43584 +Ref: -group-by43890 +Node: Indexing44327 +Ref: -elem-index44529 +Ref: -elem-indices44924 +Ref: -find-index45307 +Ref: -find-last-index45796 +Ref: -find-indices46300 +Ref: -grade-up46708 +Ref: -grade-down47111 +Node: Set operations47521 +Ref: -union47704 +Ref: -difference48146 +Ref: -intersection48563 +Ref: -powerset49000 +Ref: -permutations49213 +Ref: -distinct49513 +Node: Other list operations49837 +Ref: -rotate50062 +Ref: -repeat50357 +Ref: -cons*50620 +Ref: -snoc51007 +Ref: -interpose51420 +Ref: -interleave51718 +Ref: -zip-with52087 +Ref: -zip52804 +Ref: -zip-fill53610 +Ref: -unzip53933 +Ref: -cycle54467 +Ref: -pad54840 +Ref: -table55163 +Ref: -table-flat55953 +Ref: -first56962 +Ref: -some57334 +Ref: -last57643 +Ref: -first-item57977 +Ref: -second-item58393 +Ref: -third-item58673 +Ref: -fourth-item58951 +Ref: -fifth-item59217 +Ref: -last-item59479 +Ref: -butlast59771 +Ref: -sort60018 +Ref: -list60506 +Ref: -fix60837 +Node: Tree operations61377 +Ref: -tree-seq61573 +Ref: -tree-map62431 +Ref: -tree-map-nodes62874 +Ref: -tree-reduce63729 +Ref: -tree-reduce-from64611 +Ref: -tree-mapreduce65212 +Ref: -tree-mapreduce-from66072 +Ref: -clone67358 +Node: Threading macros67686 +Ref: ->67831 +Ref: ->>68323 +Ref: -->68828 +Ref: -as->69389 +Ref: -some->69844 +Ref: -some->>70218 +Ref: -some-->70654 +Node: Binding71125 +Ref: -when-let71337 +Ref: -when-let*71822 +Ref: -if-let72350 +Ref: -if-let*72745 +Ref: -let73362 +Ref: -let*78155 +Ref: -lambda79096 +Node: Side-effects79898 +Ref: -each80092 +Ref: -each-while80499 +Ref: -each-indexed80859 +Ref: -dotimes81377 +Ref: -doto81680 +Node: Destructive operations82107 +Ref: !cons82280 +Ref: !cdr82486 +Node: Function combinators82681 +Ref: -partial82955 +Ref: -rpartial83350 +Ref: -juxt83752 +Ref: -compose84184 +Ref: -applify84742 +Ref: -on85189 +Ref: -flip85712 +Ref: -const86024 +Ref: -cut86368 +Ref: -not86854 +Ref: -orfn87164 +Ref: -andfn87598 +Ref: -iteratefn88093 +Ref: -fixfn88796 +Ref: -prodfn90365 +Node: Development91431 +Node: Contribute91780 +Node: Changes92528 +Node: Contributors95527 +Node: Index97151 End Tag Table diff --git a/dash.texi b/dash.texi index eb741f3..e6a1ffb 100644 --- a/dash.texi +++ b/dash.texi @@ -1416,6 +1416,26 @@ Return all suffixes of @var{list} @end example @end defun +@anchor{-common-prefix} +@defun -common-prefix (&rest lists) +Return the longest common prefix of @var{lists}. + +@example +@group +(-common-prefix '(1)) + @result{} '(1) +@end group +@group +(-common-prefix '(1 2) nil '(1 2)) + @result{} nil +@end group +@group +(-common-prefix '(1 2) '(1 2 3) '(1 2 3 4)) + @result{} '(1 2) +@end group +@end example +@end defun + @anchor{-min} @defun -min (list) Return the smallest value from @var{list} of numbers or markers. diff --git a/dev/examples.el b/dev/examples.el index ed6c127..37c1fd9 100644 --- a/dev/examples.el +++ b/dev/examples.el @@ -387,6 +387,15 @@ new list." (-tails nil) => '(nil) (-tails '(1)) => '((1) nil)) + (defexamples -common-prefix + (-common-prefix '(1)) => '(1) + (-common-prefix '(1 2) () '(1 2)) => () + (-common-prefix '(1 2) '(1 2 3) '(1 2 3 4)) => '(1 2) + (-common-prefix '(())) => '(()) + (-common-prefix () ()) => () + (-common-prefix ()) => () + (-common-prefix) => ()) + (defexamples -min (-min '(0)) => 0 (-min '(3 2 1)) => 1 diff --git a/readme-template.md b/readme-template.md index 2640701..c3d7822 100644 --- a/readme-template.md +++ b/readme-template.md @@ -245,6 +245,7 @@ Change `readme-template.md` or `examples-to-docs.el` instead. - [Vasilij Schneidermann](https://github.com/wasamasa) contributed `-some`. - [William West](https://github.com/occidens) made `-fixfn` more robust at handling floats. - [Cam Saül](https://github.com/camsaul) contributed `-some->`, `-some->>`, and `-some-->`. + - [Basil L. Contovounesios](https://github.com/basil-conto) contributed `-common-prefix`. Thanks!