diff --git a/README.md b/README.md index 21b1d87..6bb5894 100644 --- a/README.md +++ b/README.md @@ -1809,8 +1809,9 @@ See also: [`-zip`](#-zip-rest-lists) #### -cycle `(list)` -Return an infinite copy of `list` that will cycle through the -elements and repeat from the beginning. +Return an infinite circular copy of `list`. +The returned list cycles through the elements of `list` and repeats +from the beginning. ```el (-take 5 (-cycle '(1 2 3))) ;; => '(1 2 3 1 2) diff --git a/dash.el b/dash.el index 2c90512..866a29b 100644 --- a/dash.el +++ b/dash.el @@ -1323,10 +1323,12 @@ See also: `-zip'" (apply '-zip lists)) (defun -cycle (list) - "Return an infinite copy of LIST that will cycle through the -elements and repeat from the beginning." + "Return an infinite circular copy of LIST. +The returned list cycles through the elements of LIST and repeats +from the beginning." (declare (pure t) (side-effect-free t)) - (let ((newlist (-map 'identity list))) + ;; Also works with sequences that aren't lists. + (let ((newlist (append list ()))) (nconc newlist newlist))) (defun -pad (fill-value &rest lists) diff --git a/dash.info b/dash.info index 8be0a07..22bebe4 100644 --- a/dash.info +++ b/dash.info @@ -1714,8 +1714,9 @@ Other list functions not fit to be classified elsewhere. ⇒ '((1 . 3) (2 . 4)) -- Function: -cycle (list) - Return an infinite copy of LIST that will cycle through the - elements and repeat from the beginning. + Return an infinite circular copy of LIST. The returned list + cycles through the elements of LIST and repeats from the + beginning. (-take 5 (-cycle '(1 2 3))) ⇒ '(1 2 3 1 2) @@ -3014,7 +3015,7 @@ Index (line 56) * -as->: Threading macros. (line 47) * -butlast: Other list operations. - (line 340) + (line 341) * -clone: Tree operations. (line 123) * -common-prefix: Reductions. (line 224) * -common-suffix: Reductions. (line 234) @@ -3047,17 +3048,17 @@ Index * -elem-index: Indexing. (line 9) * -elem-indices: Indexing. (line 21) * -fifth-item: Other list operations. - (line 320) + (line 321) * -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 234) + (line 235) * -first-item: Other list operations. - (line 271) + (line 272) * -fix: Other list operations. - (line 376) + (line 377) * -fixfn: Function combinators. (line 177) * -flatten: List to list. (line 33) @@ -3065,7 +3066,7 @@ Index * -flip: Function combinators. (line 81) * -fourth-item: Other list operations. - (line 310) + (line 311) * -grade-down: Indexing. (line 81) * -grade-up: Indexing. (line 71) * -group-by: Partitioning. (line 187) @@ -3089,13 +3090,13 @@ Index * -keep: List to list. (line 8) * -lambda: Binding. (line 253) * -last: Other list operations. - (line 261) + (line 262) * -last-item: Other list operations. - (line 330) + (line 331) * -let: Binding. (line 66) * -let*: Binding. (line 233) * -list: Other list operations. - (line 363) + (line 364) * -map: Maps. (line 10) * -map-first: Maps. (line 38) * -map-indexed: Maps. (line 66) @@ -3116,7 +3117,7 @@ Index * -orfn: Function combinators. (line 128) * -pad: Other list operations. - (line 179) + (line 180) * -partial: Function combinators. (line 9) * -partition: Partitioning. (line 74) @@ -3162,7 +3163,7 @@ Index * -running-sum: Reductions. (line 170) * -same-items?: Predicates. (line 72) * -second-item: Other list operations. - (line 286) + (line 287) * -select-by-indices: Sublist selection. (line 169) * -select-column: Sublist selection. (line 199) * -select-columns: Sublist selection. (line 180) @@ -3172,12 +3173,12 @@ Index * -snoc: Other list operations. (line 44) * -some: Other list operations. - (line 248) + (line 249) * -some-->: Threading macros. (line 84) * -some->: Threading macros. (line 60) * -some->>: Threading macros. (line 72) * -sort: Other list operations. - (line 350) + (line 351) * -splice: Maps. (line 91) * -splice-list: Maps. (line 111) * -split-at: Partitioning. (line 8) @@ -3186,15 +3187,15 @@ Index * -split-with: Partitioning. (line 17) * -sum: Reductions. (line 160) * -table: Other list operations. - (line 190) + (line 191) * -table-flat: Other list operations. - (line 209) + (line 210) * -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 298) + (line 299) * -tree-map: Tree operations. (line 28) * -tree-map-nodes: Tree operations. (line 39) * -tree-mapreduce: Tree operations. (line 85) @@ -3347,81 +3348,81 @@ Ref: -zip-lists54162 Ref: -zip-fill54863 Ref: -unzip55186 Ref: -cycle55931 -Ref: -pad56304 -Ref: -table56627 -Ref: -table-flat57417 -Ref: -first58426 -Ref: -some58798 -Ref: -last59107 -Ref: -first-item59441 -Ref: -second-item59857 -Ref: -third-item60137 -Ref: -fourth-item60415 -Ref: -fifth-item60681 -Ref: -last-item60943 -Ref: -butlast61235 -Ref: -sort61482 -Ref: -list61970 -Ref: -fix62301 -Node: Tree operations62841 -Ref: -tree-seq63037 -Ref: -tree-map63895 -Ref: -tree-map-nodes64338 -Ref: -tree-reduce65193 -Ref: -tree-reduce-from66075 -Ref: -tree-mapreduce66676 -Ref: -tree-mapreduce-from67536 -Ref: -clone68822 -Node: Threading macros69150 -Ref: ->69295 -Ref: ->>69787 -Ref: -->70292 -Ref: -as->70853 -Ref: -some->71308 -Ref: -some->>71682 -Ref: -some-->72118 -Node: Binding72589 -Ref: -when-let72801 -Ref: -when-let*73286 -Ref: -if-let73814 -Ref: -if-let*74209 -Ref: -let74826 -Ref: -let*80914 -Ref: -lambda81855 -Ref: -setq82657 -Node: Side-effects83473 -Ref: -each83667 -Ref: -each-while84074 -Ref: -each-indexed84434 -Ref: -each-r84952 -Ref: -each-r-while85385 -Ref: -dotimes85760 -Ref: -doto86063 -Ref: --doto86490 -Node: Destructive operations86765 -Ref: !cons86938 -Ref: !cdr87144 -Node: Function combinators87339 -Ref: -partial87613 -Ref: -rpartial88006 -Ref: -juxt88408 -Ref: -compose88840 -Ref: -applify89398 -Ref: -on89829 -Ref: -flip90355 -Ref: -const90667 -Ref: -cut91011 -Ref: -not91497 -Ref: -orfn91807 -Ref: -andfn92241 -Ref: -iteratefn92736 -Ref: -fixfn93439 -Ref: -prodfn95008 -Node: Development96077 -Node: Contribute96426 -Node: Changes97174 -Node: Contributors100173 -Node: Index101797 +Ref: -pad56338 +Ref: -table56661 +Ref: -table-flat57451 +Ref: -first58460 +Ref: -some58832 +Ref: -last59141 +Ref: -first-item59475 +Ref: -second-item59891 +Ref: -third-item60171 +Ref: -fourth-item60449 +Ref: -fifth-item60715 +Ref: -last-item60977 +Ref: -butlast61269 +Ref: -sort61516 +Ref: -list62004 +Ref: -fix62335 +Node: Tree operations62875 +Ref: -tree-seq63071 +Ref: -tree-map63929 +Ref: -tree-map-nodes64372 +Ref: -tree-reduce65227 +Ref: -tree-reduce-from66109 +Ref: -tree-mapreduce66710 +Ref: -tree-mapreduce-from67570 +Ref: -clone68856 +Node: Threading macros69184 +Ref: ->69329 +Ref: ->>69821 +Ref: -->70326 +Ref: -as->70887 +Ref: -some->71342 +Ref: -some->>71716 +Ref: -some-->72152 +Node: Binding72623 +Ref: -when-let72835 +Ref: -when-let*73320 +Ref: -if-let73848 +Ref: -if-let*74243 +Ref: -let74860 +Ref: -let*80948 +Ref: -lambda81889 +Ref: -setq82691 +Node: Side-effects83507 +Ref: -each83701 +Ref: -each-while84108 +Ref: -each-indexed84468 +Ref: -each-r84986 +Ref: -each-r-while85419 +Ref: -dotimes85794 +Ref: -doto86097 +Ref: --doto86524 +Node: Destructive operations86799 +Ref: !cons86972 +Ref: !cdr87178 +Node: Function combinators87373 +Ref: -partial87647 +Ref: -rpartial88040 +Ref: -juxt88442 +Ref: -compose88874 +Ref: -applify89432 +Ref: -on89863 +Ref: -flip90389 +Ref: -const90701 +Ref: -cut91045 +Ref: -not91531 +Ref: -orfn91841 +Ref: -andfn92275 +Ref: -iteratefn92770 +Ref: -fixfn93473 +Ref: -prodfn95042 +Node: Development96111 +Node: Contribute96460 +Node: Changes97208 +Node: Contributors100207 +Node: Index101831  End Tag Table diff --git a/dash.texi b/dash.texi index 6ef77eb..c6864ee 100644 --- a/dash.texi +++ b/dash.texi @@ -2731,8 +2731,9 @@ See also: @code{-zip} (@pxref{-zip}) @anchor{-cycle} @defun -cycle (list) -Return an infinite copy of @var{list} that will cycle through the -elements and repeat from the beginning. +Return an infinite circular copy of @var{list}. +The returned list cycles through the elements of @var{list} and repeats +from the beginning. @example @group diff --git a/dev/examples.el b/dev/examples.el index 5c37b3e..4997f5b 100644 --- a/dev/examples.el +++ b/dev/examples.el @@ -782,7 +782,8 @@ new list." (-take 7 (-cycle '(1 "and" 3))) => '(1 "and" 3 1 "and" 3 1) (-zip (-cycle '(1 2 3)) '(1 2)) => '((1 . 1) (2 . 2)) (-zip-with 'cons (-cycle '(1 2 3)) '(1 2)) => '((1 . 1) (2 . 2)) - (-map (-partial '-take 5) (-split-at 5 (-cycle '(1 2 3)))) => '((1 2 3 1 2) (3 1 2 3 1))) + (-map (-partial '-take 5) (-split-at 5 (-cycle '(1 2 3)))) => '((1 2 3 1 2) (3 1 2 3 1)) + (let ((l (list 1))) (eq l (-cycle l))) => nil) (defexamples -pad (-pad 0 '()) => '(())