feat: add -zip-lists

master
Matus Goljer 6 years ago
parent 800c25d1e8
commit 52fd01071a
No known key found for this signature in database
GPG Key ID: FA5A172CF1800B80
  1. 31
      dash.el
  2. 436
      dash.info
  3. 47
      dash.texi
  4. 13
      dev/examples.el
  5. 3
      readme-template.md

@ -1263,6 +1263,24 @@ The anaphoric form `--zip-with' binds the elements from LIST1 as symbol `it',
and the elements from LIST2 as symbol `other'."
(--zip-with (funcall fn it other) list1 list2))
(defun -zip-lists (&rest lists)
"Zip LISTS together. Group the head of each list, followed by the
second elements of each list, and so on. The lengths of the returned
groupings are equal to the length of the shortest input list.
The return value is always list of lists, which is a difference
from `-zip-pair' which returns a cons-cell in case two input
lists are provided.
See also: `-zip'"
(declare (pure t) (side-effect-free t))
(when lists
(let (results)
(while (-none? 'null lists)
(setq results (cons (mapcar 'car lists) results))
(setq lists (mapcar 'cdr lists)))
(nreverse results))))
(defun -zip (&rest lists)
"Zip LISTS together. Group the head of each list, followed by the
second elements of each list, and so on. The lengths of the returned
@ -1271,11 +1289,12 @@ groupings are equal to the length of the shortest input list.
If two lists are provided as arguments, return the groupings as a list
of cons cells. Otherwise, return the groupings as a list of lists.
Please note! This distinction is being removed in an upcoming 3.0
release of Dash. If you rely on this behavior, use `-zip-pair` instead,
which will retain that behaviour in future versions.
Use `-zip-lists' if you need the return value to always be a list
of lists.
Alias: `-zip-pair'
Alias: `-zip-pair'"
See also: `-zip-lists'"
(declare (pure t) (side-effect-free t))
(when lists
(let (results)
@ -1308,6 +1327,9 @@ a variable number of arguments, such that
is identity (given that the lists are the same length).
Note in particular that calling this on a list of two lists will
return a list of cons-cells such that the aboce identity works.
See also: `-zip'"
(apply '-zip lists))
@ -2921,6 +2943,7 @@ structure such as plist or alist."
"--zip-with"
"-zip"
"-zip-fill"
"-zip-lists"
"-zip-pair"
"-cycle"
"-pad"

@ -1,4 +1,4 @@
This is dash.info, produced by makeinfo version 6.6 from dash.texi.
This is dash.info, produced by makeinfo version 6.5 from dash.texi.
This manual is for ‘dash.el’ version 2.12.1.
@ -1643,16 +1643,38 @@ Other list functions not fit to be classified elsewhere.
list of cons cells. Otherwise, return the groupings as a list of
lists.
Please note! This distinction is being removed in an upcoming
3.0 release of Dash. If you rely on this behavior, use -zip-pair
instead.
Use ‘-zip-lists’ (*note -zip-lists::) if you need the return
value to always be a list of lists.
Alias: ‘-zip-pair’
See also: ‘-zip-lists’ (*note -zip-lists::)
(-zip '(1 2 3) '(4 5 6))
⇒ '((1 . 4) (2 . 5) (3 . 6))
(-zip '(1 2 3) '(4 5 6 7))
⇒ '((1 . 4) (2 . 5) (3 . 6))
(-zip '(1 2 3 4) '(4 5 6))
⇒ '((1 . 4) (2 . 5) (3 . 6))
(-zip '(1 2) '(3 4 5) '(6))
⇒ '((1 3 6))
-- Function: -zip-lists (&rest lists)
Zip LISTS together. Group the head of each list, followed by the
second elements of each list, and so on. The lengths of the
returned groupings are equal to the length of the shortest input
list.
The return value is always list of lists, which is a difference
from ‘-zip-pair’ which returns a cons-cell in case two input
lists are provided.
See also: ‘-zip’ (*note -zip::)
(-zip-lists '(1 2 3) '(4 5 6))
⇒ '((1 4) (2 5) (3 6))
(-zip-lists '(1 2 3) '(4 5 6 7))
⇒ '((1 4) (2 5) (3 6))
(-zip-lists '(1 2) '(3 4 5) '(6))
⇒ '((1 3 6))
-- Function: -zip-fill (fill-value &rest lists)
Zip LISTS, with FILL-VALUE padded onto the shorter lists. The
@ -1672,12 +1694,17 @@ Other list functions not fit to be classified elsewhere.
is identity (given that the lists are the same length).
Note in particular that calling this on a list of two lists will
return a list of cons-cells such that the aboce identity works.
See also: ‘-zip’ (*note -zip::)
(-unzip (-zip '(1 2 3) '(a b c) '("e" "f" "g")))
⇒ '((1 2 3) (a b c) ("e" "f" "g"))
(-unzip '((1 2) (3 4) (5 6) (7 8) (9 10)))
⇒ '((1 3 5 7 9) (2 4 6 8 10))
(-unzip '((1 2) (3 4)))
⇒ '((1 . 3) (2 . 4))
-- Function: -cycle (list)
Return an infinite copy of LIST that will cycle through the
@ -2980,7 +3007,7 @@ Index
(line 56)
* -as->: Threading macros. (line 47)
* -butlast: Other list operations.
(line 313)
(line 340)
* -clone: Tree operations. (line 123)
* -common-prefix: Reductions. (line 224)
* -common-suffix: Reductions. (line 234)
@ -2997,7 +3024,7 @@ Index
* -cut: Function combinators.
(line 106)
* -cycle: Other list operations.
(line 141)
(line 168)
* -difference: Set operations. (line 20)
* -distinct: Set operations. (line 62)
* -dotimes: Side-effects. (line 61)
@ -3013,17 +3040,17 @@ Index
* -elem-index: Indexing. (line 9)
* -elem-indices: Indexing. (line 21)
* -fifth-item: Other list operations.
(line 293)
(line 320)
* -filter: Sublist selection. (line 8)
* -find-index: Indexing. (line 32)
* -find-indices: Indexing. (line 60)
* -find-last-index: Indexing. (line 46)
* -first: Other list operations.
(line 207)
(line 234)
* -first-item: Other list operations.
(line 244)
(line 271)
* -fix: Other list operations.
(line 349)
(line 376)
* -fixfn: Function combinators.
(line 177)
* -flatten: List to list. (line 33)
@ -3031,7 +3058,7 @@ Index
* -flip: Function combinators.
(line 81)
* -fourth-item: Other list operations.
(line 283)
(line 310)
* -grade-down: Indexing. (line 81)
* -grade-up: Indexing. (line 71)
* -group-by: Partitioning. (line 187)
@ -3055,13 +3082,13 @@ Index
* -keep: List to list. (line 8)
* -lambda: Binding. (line 253)
* -last: Other list operations.
(line 234)
(line 261)
* -last-item: Other list operations.
(line 303)
(line 330)
* -let: Binding. (line 66)
* -let*: Binding. (line 233)
* -list: Other list operations.
(line 336)
(line 363)
* -map: Maps. (line 10)
* -map-first: Maps. (line 38)
* -map-indexed: Maps. (line 66)
@ -3082,7 +3109,7 @@ Index
* -orfn: Function combinators.
(line 128)
* -pad: Other list operations.
(line 152)
(line 179)
* -partial: Function combinators.
(line 9)
* -partition: Partitioning. (line 74)
@ -3128,7 +3155,7 @@ Index
* -running-sum: Reductions. (line 170)
* -same-items?: Predicates. (line 72)
* -second-item: Other list operations.
(line 259)
(line 286)
* -select-by-indices: Sublist selection. (line 169)
* -select-column: Sublist selection. (line 199)
* -select-columns: Sublist selection. (line 180)
@ -3138,12 +3165,12 @@ Index
* -snoc: Other list operations.
(line 44)
* -some: Other list operations.
(line 221)
(line 248)
* -some-->: Threading macros. (line 84)
* -some->: Threading macros. (line 60)
* -some->>: Threading macros. (line 72)
* -sort: Other list operations.
(line 323)
(line 350)
* -splice: Maps. (line 91)
* -splice-list: Maps. (line 111)
* -split-at: Partitioning. (line 8)
@ -3152,15 +3179,15 @@ Index
* -split-with: Partitioning. (line 17)
* -sum: Reductions. (line 160)
* -table: Other list operations.
(line 163)
(line 190)
* -table-flat: Other list operations.
(line 182)
(line 209)
* -tails: Reductions. (line 214)
* -take: Sublist selection. (line 102)
* -take-last: Sublist selection. (line 113)
* -take-while: Sublist selection. (line 147)
* -third-item: Other list operations.
(line 271)
(line 298)
* -tree-map: Tree operations. (line 28)
* -tree-map-nodes: Tree operations. (line 39)
* -tree-mapreduce: Tree operations. (line 85)
@ -3171,14 +3198,16 @@ Index
* -unfold: Unfolding. (line 25)
* -union: Set operations. (line 8)
* -unzip: Other list operations.
(line 124)
(line 146)
* -update-at: List to list. (line 133)
* -when-let: Binding. (line 9)
* -when-let*: Binding. (line 23)
* -zip: Other list operations.
(line 95)
* -zip-fill: Other list operations.
(line 116)
(line 138)
* -zip-lists: Other list operations.
(line 119)
* -zip-with: Other list operations.
(line 79)
@ -3207,184 +3236,185 @@ Ref: -remove10524
Ref: -remove-first10935
Ref: -remove-last11462
Ref: -remove-item11983
Ref: -non-nil12377
Ref: -slice12536
Ref: -take13068
Ref: -take-last13376
Ref: -drop13699
Ref: -drop-last13972
Ref: -take-while14232
Ref: -drop-while14582
Ref: -select-by-indices14938
Ref: -select-columns15452
Ref: -select-column16157
Node: List to list16620
Ref: -keep16812
Ref: -concat17315
Ref: -flatten17612
Ref: -flatten-n18371
Ref: -replace18758
Ref: -replace-first19221
Ref: -replace-last19717
Ref: -insert-at20206
Ref: -replace-at20533
Ref: -update-at20928
Ref: -remove-at21419
Ref: -remove-at-indices21907
Node: Reductions22489
Ref: -reduce-from22658
Ref: -reduce-r-from23424
Ref: -reduce24191
Ref: -reduce-r24925
Ref: -reductions-from25795
Ref: -reductions-r-from26510
Ref: -reductions27235
Ref: -reductions-r27860
Ref: -count28495
Ref: -sum28719
Ref: -running-sum28908
Ref: -product29201
Ref: -running-product29410
Ref: -inits29723
Ref: -tails29971
Ref: -common-prefix30218
Ref: -common-suffix30515
Ref: -min30812
Ref: -min-by31038
Ref: -max31561
Ref: -max-by31786
Node: Unfolding32314
Ref: -iterate32553
Ref: -unfold32998
Node: Predicates33806
Ref: -any?33930
Ref: -all?34250
Ref: -none?34580
Ref: -only-some?34882
Ref: -contains?35367
Ref: -same-items?35756
Ref: -is-prefix?36141
Ref: -is-suffix?36464
Ref: -is-infix?36787
Node: Partitioning37141
Ref: -split-at37329
Ref: -split-with37614
Ref: -split-on38017
Ref: -split-when38693
Ref: -separate39333
Ref: -partition39775
Ref: -partition-all40227
Ref: -partition-in-steps40655
Ref: -partition-all-in-steps41152
Ref: -partition-by41637
Ref: -partition-by-header42019
Ref: -partition-after-pred42623
Ref: -partition-before-pred42967
Ref: -partition-before-item43318
Ref: -partition-after-item43629
Ref: -group-by43935
Node: Indexing44372
Ref: -elem-index44574
Ref: -elem-indices44969
Ref: -find-index45352
Ref: -find-last-index45841
Ref: -find-indices46345
Ref: -grade-up46753
Ref: -grade-down47156
Node: Set operations47566
Ref: -union47749
Ref: -difference48191
Ref: -intersection48608
Ref: -powerset49045
Ref: -permutations49258
Ref: -distinct49558
Node: Other list operations49936
Ref: -rotate50161
Ref: -repeat50531
Ref: -cons*50794
Ref: -snoc51181
Ref: -interpose51594
Ref: -interleave51892
Ref: -zip-with52261
Ref: -zip52978
Ref: -zip-fill53784
Ref: -unzip54107
Ref: -cycle54641
Ref: -pad55014
Ref: -table55337
Ref: -table-flat56127
Ref: -first57136
Ref: -some57508
Ref: -last57817
Ref: -first-item58151
Ref: -second-item58567
Ref: -third-item58847
Ref: -fourth-item59125
Ref: -fifth-item59391
Ref: -last-item59653
Ref: -butlast59945
Ref: -sort60192
Ref: -list60680
Ref: -fix61011
Node: Tree operations61551
Ref: -tree-seq61747
Ref: -tree-map62605
Ref: -tree-map-nodes63048
Ref: -tree-reduce63903
Ref: -tree-reduce-from64785
Ref: -tree-mapreduce65386
Ref: -tree-mapreduce-from66246
Ref: -clone67532
Node: Threading macros67860
Ref: ->68005
Ref: ->>68497
Ref: -->69002
Ref: -as->69563
Ref: -some->70018
Ref: -some->>70392
Ref: -some-->70828
Node: Binding71299
Ref: -when-let71511
Ref: -when-let*71996
Ref: -if-let72524
Ref: -if-let*72919
Ref: -let73536
Ref: -let*79624
Ref: -lambda80565
Ref: -setq81367
Node: Side-effects82183
Ref: -each82377
Ref: -each-while82784
Ref: -each-indexed83144
Ref: -each-r83662
Ref: -each-r-while84095
Ref: -dotimes84470
Ref: -doto84773
Ref: --doto85200
Node: Destructive operations85475
Ref: !cons85648
Ref: !cdr85854
Node: Function combinators86049
Ref: -partial86323
Ref: -rpartial86718
Ref: -juxt87120
Ref: -compose87552
Ref: -applify88110
Ref: -on88541
Ref: -flip89067
Ref: -const89379
Ref: -cut89723
Ref: -not90209
Ref: -orfn90519
Ref: -andfn90953
Ref: -iteratefn91448
Ref: -fixfn92151
Ref: -prodfn93720
Node: Development94789
Node: Contribute95138
Node: Changes95886
Node: Contributors98885
Node: Index100509
Ref: -non-nil12378
Ref: -slice12537
Ref: -take13069
Ref: -take-last13377
Ref: -drop13700
Ref: -drop-last13973
Ref: -take-while14233
Ref: -drop-while14583
Ref: -select-by-indices14939
Ref: -select-columns15453
Ref: -select-column16158
Node: List to list16621
Ref: -keep16813
Ref: -concat17316
Ref: -flatten17613
Ref: -flatten-n18372
Ref: -replace18759
Ref: -replace-first19222
Ref: -replace-last19719
Ref: -insert-at20209
Ref: -replace-at20536
Ref: -update-at20931
Ref: -remove-at21422
Ref: -remove-at-indices21910
Node: Reductions22492
Ref: -reduce-from22661
Ref: -reduce-r-from23427
Ref: -reduce24194
Ref: -reduce-r24928
Ref: -reductions-from25798
Ref: -reductions-r-from26513
Ref: -reductions27238
Ref: -reductions-r27863
Ref: -count28498
Ref: -sum28722
Ref: -running-sum28911
Ref: -product29204
Ref: -running-product29413
Ref: -inits29726
Ref: -tails29974
Ref: -common-prefix30221
Ref: -common-suffix30518
Ref: -min30815
Ref: -min-by31041
Ref: -max31564
Ref: -max-by31789
Node: Unfolding32317
Ref: -iterate32556
Ref: -unfold33001
Node: Predicates33809
Ref: -any?33933
Ref: -all?34253
Ref: -none?34583
Ref: -only-some?34885
Ref: -contains?35370
Ref: -same-items?35759
Ref: -is-prefix?36144
Ref: -is-suffix?36467
Ref: -is-infix?36790
Node: Partitioning37144
Ref: -split-at37332
Ref: -split-with37617
Ref: -split-on38020
Ref: -split-when38696
Ref: -separate39336
Ref: -partition39778
Ref: -partition-all40230
Ref: -partition-in-steps40658
Ref: -partition-all-in-steps41155
Ref: -partition-by41640
Ref: -partition-by-header42022
Ref: -partition-after-pred42626
Ref: -partition-before-pred42970
Ref: -partition-before-item43321
Ref: -partition-after-item43632
Ref: -group-by43938
Node: Indexing44375
Ref: -elem-index44577
Ref: -elem-indices44972
Ref: -find-index45355
Ref: -find-last-index45844
Ref: -find-indices46348
Ref: -grade-up46756
Ref: -grade-down47159
Node: Set operations47569
Ref: -union47752
Ref: -difference48194
Ref: -intersection48611
Ref: -powerset49048
Ref: -permutations49261
Ref: -distinct49561
Node: Other list operations49939
Ref: -rotate50164
Ref: -repeat50534
Ref: -cons*50797
Ref: -snoc51184
Ref: -interpose51597
Ref: -interleave51895
Ref: -zip-with52264
Ref: -zip52981
Ref: -zip-lists53813
Ref: -zip-fill54514
Ref: -unzip54837
Ref: -cycle55582
Ref: -pad55955
Ref: -table56278
Ref: -table-flat57068
Ref: -first58077
Ref: -some58449
Ref: -last58758
Ref: -first-item59092
Ref: -second-item59508
Ref: -third-item59788
Ref: -fourth-item60066
Ref: -fifth-item60332
Ref: -last-item60594
Ref: -butlast60886
Ref: -sort61133
Ref: -list61621
Ref: -fix61952
Node: Tree operations62492
Ref: -tree-seq62688
Ref: -tree-map63546
Ref: -tree-map-nodes63989
Ref: -tree-reduce64844
Ref: -tree-reduce-from65726
Ref: -tree-mapreduce66327
Ref: -tree-mapreduce-from67187
Ref: -clone68473
Node: Threading macros68801
Ref: ->68946
Ref: ->>69438
Ref: -->69943
Ref: -as->70504
Ref: -some->70959
Ref: -some->>71333
Ref: -some-->71769
Node: Binding72240
Ref: -when-let72452
Ref: -when-let*72937
Ref: -if-let73465
Ref: -if-let*73860
Ref: -let74477
Ref: -let*80565
Ref: -lambda81506
Ref: -setq82308
Node: Side-effects83124
Ref: -each83318
Ref: -each-while83725
Ref: -each-indexed84085
Ref: -each-r84603
Ref: -each-r-while85036
Ref: -dotimes85411
Ref: -doto85714
Ref: --doto86141
Node: Destructive operations86416
Ref: !cons86589
Ref: !cdr86795
Node: Function combinators86990
Ref: -partial87264
Ref: -rpartial87659
Ref: -juxt88061
Ref: -compose88493
Ref: -applify89051
Ref: -on89498
Ref: -flip90024
Ref: -const90336
Ref: -cut90680
Ref: -not91166
Ref: -orfn91476
Ref: -andfn91910
Ref: -iteratefn92405
Ref: -fixfn93108
Ref: -prodfn94676
Node: Development95745
Node: Contribute96094
Node: Changes96842
Node: Contributors99841
Node: Index101465

End Tag Table

@ -2624,8 +2624,12 @@ groupings are equal to the length of the shortest input list.
If two lists are provided as arguments, return the groupings as a list
of cons cells. Otherwise, return the groupings as a list of lists.
Please note! This distinction is being removed in an upcoming 3.0
release of Dash. If you rely on this behavior, use -zip-pair instead.
Use @code{-zip-lists} (@pxref{-zip-lists}) if you need the return value to always be a list
of lists.
Alias: @code{-zip-pair}
See also: @code{-zip-lists} (@pxref{-zip-lists})
@example
@group
@ -2637,8 +2641,36 @@ release of Dash. If you rely on this behavior, use -zip-pair instead.
@result{} '((1 . 4) (2 . 5) (3 . 6))
@end group
@group
(-zip '(1 2 3 4) '(4 5 6))
@result{} '((1 . 4) (2 . 5) (3 . 6))
(-zip '(1 2) '(3 4 5) '(6))
@result{} '((1 3 6))
@end group
@end example
@end defun
@anchor{-zip-lists}
@defun -zip-lists (&rest lists)
Zip @var{lists} together. Group the head of each list, followed by the
second elements of each list, and so on. The lengths of the returned
groupings are equal to the length of the shortest input list.
The return value is always list of lists, which is a difference
from @code{-zip-pair} which returns a cons-cell in case two input
lists are provided.
See also: @code{-zip} (@pxref{-zip})
@example
@group
(-zip-lists '(1 2 3) '(4 5 6))
@result{} '((1 4) (2 5) (3 6))
@end group
@group
(-zip-lists '(1 2 3) '(4 5 6 7))
@result{} '((1 4) (2 5) (3 6))
@end group
@group
(-zip-lists '(1 2) '(3 4 5) '(6))
@result{} '((1 3 6))
@end group
@end example
@end defun
@ -2668,6 +2700,9 @@ a variable number of arguments, such that
is identity (given that the lists are the same length).
Note in particular that calling this on a list of two lists will
return a list of cons-cells such that the aboce identity works.
See also: @code{-zip} (@pxref{-zip})
@example
@ -2679,6 +2714,10 @@ See also: @code{-zip} (@pxref{-zip})
(-unzip '((1 2) (3 4) (5 6) (7 8) (9 10)))
@result{} '((1 3 5 7 9) (2 4 6 8 10))
@end group
@group
(-unzip '((1 2) (3 4)))
@result{} '((1 . 3) (2 . 4))
@end group
@end example
@end defun

@ -756,17 +756,26 @@ new list."
(defexamples -zip
(-zip '(1 2 3) '(4 5 6)) => '((1 . 4) (2 . 5) (3 . 6))
(-zip '(1 2 3) '(4 5 6 7)) => '((1 . 4) (2 . 5) (3 . 6))
(-zip '(1 2) '(3 4 5) '(6)) => '((1 3 6))
(-zip '(1 2 3 4) '(4 5 6)) => '((1 . 4) (2 . 5) (3 . 6))
(-zip '(1 2 3) '(4 5 6) '(7 8 9)) => '((1 4 7) (2 5 8) (3 6 9))
(-zip '(1 2) '(3 4 5) '(6)) => '((1 3 6))
(-zip) => nil)
(defexamples -zip-lists
(-zip-lists '(1 2 3) '(4 5 6)) => '((1 4) (2 5) (3 6))
(-zip-lists '(1 2 3) '(4 5 6 7)) => '((1 4) (2 5) (3 6))
(-zip-lists '(1 2) '(3 4 5) '(6)) => '((1 3 6))
(-zip-lists '(1 2 3 4) '(4 5 6)) => '((1 4) (2 5) (3 6))
(-zip-lists '(1 2 3) '(4 5 6) '(7 8 9)) => '((1 4 7) (2 5 8) (3 6 9))
(-zip-lists) => nil)
(defexamples -zip-fill
(-zip-fill 0 '(1 2 3 4 5) '(6 7 8 9)) => '((1 . 6) (2 . 7) (3 . 8) (4 . 9) (5 . 0)))
(defexamples -unzip
(-unzip (-zip '(1 2 3) '(a b c) '("e" "f" "g"))) => '((1 2 3) (a b c) ("e" "f" "g"))
(-unzip '((1 2) (3 4) (5 6) (7 8) (9 10))) => '((1 3 5 7 9) (2 4 6 8 10)))
(-unzip '((1 2) (3 4) (5 6) (7 8) (9 10))) => '((1 3 5 7 9) (2 4 6 8 10))
(-unzip '((1 2) (3 4))) => '((1 . 3) (2 . 4)))
(defexamples -cycle
(-take 5 (-cycle '(1 2 3))) => '(1 2 3 1 2)

@ -30,7 +30,8 @@ To get function combinators:
- For backward compatibility reasons `-zip` return a cons-cell instead of a list
with two elements when called on two lists. This is a clunky API, and in an
upcoming 3.0 release of Dash it will always return a list. If you rely on the
cons-cell return value, use `-zip-pair` instead.
cons-cell return value, use `-zip-pair` instead. During the 2.x
release cycle the new API is available as `-zip-lists`.
## Syntax highlighting of dash functions

Loading…
Cancel
Save