iterator-helper
Advanced tools
Comparing version 1.3.1 to 1.3.2
{ | ||
"name": "iterator-helper", | ||
"version": "1.3.1", | ||
"version": "1.3.2", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -249,1 +249,21 @@ # iterator-helper | ||
``` | ||
### Example | ||
```ts | ||
for (const i of iter.range(10)) { | ||
// i will goes from 0 to 9 (included) | ||
} | ||
for (const _ of iter.repeat(null, 10)) { | ||
// This loop content will be executed 10 times | ||
} | ||
iter.repeat({ id: 1, name: 'Sialae' }) // Create an infinite iterator that yield { id: 1, name: 'Sialae' } | ||
.asIndexedPairs() // Yield [index, element] | ||
.map(([index, item]) => ({ ...item, id: index + 1 })) // For [index, element], returns { ...element, id: index + 1 } | ||
.filter(item => item.id % 2 !== 0) // Yield only elements with element.id % 2 !== 0 | ||
.take(3) // Yield 3 items maximum then close the iterator | ||
.toArray(); // Store the remaining iterator items into an array (3 elements) | ||
// Result: [{ name: 'Sialae', id: 0 }, { name: 'Sialae', id: 2 }, { name: 'Sialae', id: 4 }] | ||
``` |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
128108
269