@odiak/iterate
TypeScript icon, indicating that this package has built-in type declarations

0.0.4 • Public • Published

@odiak/iterate

@odiak/iterate provides wrapper for JavaScript's iterable object. They have some useful methods like map,filter and reduce and are also iterable themself.

Example

import { iterate, range } from '@odiak/iterate'

const iterable: Iterable<number> = [1, 1, 2, 3, 5, 8, 13, 21]
const wrapped = iterate(iterable)
  .map((n) => n + 1)
  .filter((n) => n % 3 === 0)
  .map((n) => `${n}!`)

for (const s of wrapped) {
  console.log(s)
}
// -> 3! and 21! are printed

const x = range(10)
  .filter((n) => n % 2 !== 0)
  .map((n) => n ** 2)
  .reduce((s, n) => s + n, 0)

console.log(x)
// -> 165 is printed

License

MIT

Readme

Keywords

none

Package Sidebar

Install

npm i @odiak/iterate

Weekly Downloads

4

Version

0.0.4

License

MIT

Unpacked Size

4.12 kB

Total Files

6

Last publish

Collaborators

  • odiak