| 22 | import isArrayLike from './utils/isArrayLike'; |
| 23 | |
| 24 | export class Seq extends Collection { |
| 25 | constructor(value) { |
| 26 | // eslint-disable-next-line no-constructor-return |
| 27 | return value === undefined || value === null |
| 28 | ? emptySequence() |
| 29 | : isImmutable(value) |
| 30 | ? value.toSeq() |
| 31 | : seqFromValue(value); |
| 32 | } |
| 33 | |
| 34 | toSeq() { |
| 35 | return this; |
| 36 | } |
| 37 | |
| 38 | toString() { |
| 39 | return this.__toString('Seq {', '}'); |
| 40 | } |
| 41 | |
| 42 | cacheResult() { |
| 43 | if (!this._cache && this.__iterateUncached) { |
| 44 | this._cache = this.entrySeq().toArray(); |
| 45 | this.size = this._cache.length; |
| 46 | } |
| 47 | return this; |
| 48 | } |
| 49 | |
| 50 | // abstract __iterateUncached(fn, reverse) |
| 51 | |
| 52 | __iterate(fn, reverse) { |
| 53 | const cache = this._cache; |
| 54 | if (cache) { |
| 55 | const size = cache.length; |
| 56 | let i = 0; |
| 57 | while (i !== size) { |
| 58 | const entry = cache[reverse ? size - ++i : i++]; |
| 59 | if (fn(entry[1], entry[0], this) === false) { |
| 60 | break; |
| 61 | } |
| 62 | } |
| 63 | return i; |
| 64 | } |
| 65 | return this.__iterateUncached(fn, reverse); |
| 66 | } |
| 67 | |
| 68 | // abstract __iteratorUncached(type, reverse) |
| 69 | |
| 70 | __iterator(type, reverse) { |
| 71 | const cache = this._cache; |
| 72 | if (cache) { |
| 73 | const size = cache.length; |
| 74 | let i = 0; |
| 75 | return new Iterator(() => { |
| 76 | if (i === size) { |
| 77 | return iteratorDone(); |
| 78 | } |
| 79 | const entry = cache[reverse ? size - ++i : i++]; |
| 80 | return iteratorValue(type, entry[0], entry[1]); |
| 81 | }); |
no outgoing calls
no test coverage detected