MCPcopy Index your code
hub / github.com/immutable-js/immutable-js / Repeat

Class Repeat

src/Repeat.js:12–99  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

10 * undefined, returns an infinite sequence of `value`.
11 */
12export class Repeat extends IndexedSeq {
13 constructor(value, times) {
14 if (!(this instanceof Repeat)) {
15 // eslint-disable-next-line no-constructor-return
16 return new Repeat(value, times);
17 }
18 this._value = value;
19 this.size = times === undefined ? Infinity : Math.max(0, times);
20 if (this.size === 0) {
21 if (EMPTY_REPEAT) {
22 // eslint-disable-next-line no-constructor-return
23 return EMPTY_REPEAT;
24 }
25 // eslint-disable-next-line @typescript-eslint/no-this-alias
26 EMPTY_REPEAT = this;
27 }
28 }
29
30 toString() {
31 if (this.size === 0) {
32 return 'Repeat []';
33 }
34 return 'Repeat [ ' + this._value + ' ' + this.size + ' times ]';
35 }
36
37 get(index, notSetValue) {
38 return this.has(index) ? this._value : notSetValue;
39 }
40
41 includes(searchValue) {
42 return is(this._value, searchValue);
43 }
44
45 slice(begin, end) {
46 const size = this.size;
47 return wholeSlice(begin, end, size)
48 ? this
49 : new Repeat(
50 this._value,
51 resolveEnd(end, size) - resolveBegin(begin, size)
52 );
53 }
54
55 reverse() {
56 return this;
57 }
58
59 indexOf(searchValue) {
60 if (this.size !== 0 && is(this._value, searchValue)) {
61 return 0;
62 }
63 return -1;
64 }
65
66 lastIndexOf(searchValue) {
67 if (this.size !== 0 && is(this._value, searchValue)) {
68 return this.size - 1;
69 }

Callers 4

immutable-flow.jsFile · 0.85
repeat.tsFile · 0.85
Repeat.tsFile · 0.85
toSeq.tsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected