UNPKG

1.54 kBMarkdownView Raw
1Gives values that cycle through an iterable.
2[:package:](https://www.npmjs.com/package/@extra-iterable/cycle)
3[:smiley_cat:](https://github.com/orgs/nodef/packages?repo_name=extra-iterable)
4[:running:](https://npm.runkit.com/@extra-iterable/cycle)
5[:vhs:](https://asciinema.org/a/339734)
6[:moon:](https://www.npmjs.com/package/@extra-iterable/cycle.min)
7[:scroll:](https://unpkg.com/@extra-iterable/cycle/)
8[:newspaper:](https://nodef.github.io/extra-iterable/)
9[:blue_book:](https://github.com/nodef/extra-iterable/wiki/)
10
11> Similar: [repeat], [cycle], [rotate], [reverse].
12
13> This is part of package [extra-iterable].
14
15[extra-iterable]: https://www.npmjs.com/package/extra-iterable
16
17<br>
18
19```javascript
20iterable.cycle(x, [i], [n]);
21// x: an iterable
22// i: start index (0)
23// n: number of values (-1 => Inf)
24```
25
26```javascript
27const iterable = require("extra-iterable");
28
29var x = [1, 2, 3];
30[...iterable.cycle(x, 0, 2)];
31// [ 1, 2 ]
32
33[...iterable.cycle(x, 0, 4)];
34// [ 1, 2, 3, 1 ]
35
36[...iterable.cycle(x, 1, 6)];
37// [ 2, 3, 1, 2, 3, 1 ]
38```
39
40<br>
41<br>
42
43
44## References
45
46- [List-Extra.cycle: elm](https://package.elm-lang.org/packages/elm-community/list-extra/7.1.0/List-Extra#cycle)
47- [Data.List.cycle: Haskell](https://hackage.haskell.org/package/base-4.12.0.0/docs/Data-List.html#v:cycle)
48
49[repeat]: https://github.com/nodef/extra-iterable/wiki/repeat
50[cycle]: https://github.com/nodef/extra-iterable/wiki/cycle
51[rotate]: https://github.com/nodef/extra-iterable/wiki/rotate
52[reverse]: https://github.com/nodef/extra-iterable/wiki/reverse