slothfuliter
TypeScript icon, indicating that this package has built-in type declarations

0.0.5 • Public • Published

Sloth lazily moving from box to box

slothfuliter

Slothful Iterables brings the power of Array functions like filter, map, forEach to JavaScript's iterators and generators

You can now lazily run transformations on data to create powerful stream operations while keeping your server's memory usage low.

Installation and Usage

npm install slothfuliter

Infinite Iterable

infinite can be used to create a sequence of an infinitely sized sequence of a single value.

The below example shows it being used to output the current Date for the next 10 seconds.

import { infinite } from "slothfuliter"

const end = new Date(Date.now() + 10_000)

infinite(1)
.map(_ => new Date())
.takeWhile(now => now < end)
.forEach(now => console.log(now))

Range Iterable

range can be used to create a fixed size sequence of numbers given a starting number and a length.

The below example shows it being used to output the first 15 fibonacci numbers.

import { range } from "slothfuliter"

const SQRT_FIVE = Math.sqrt(5)

range(0, 15)
.map(i => (1 / SQRT_FIVE) * (Math.pow((1 + SQRT_FIVE) / 2, i) - Math.pow((1 - SQRT_FIVE) / 2, i)))
.map(Math.floor)
.forEach(i => console.log(i))

Package Sidebar

Install

npm i slothfuliter

Weekly Downloads

45

Version

0.0.5

License

MIT

Unpacked Size

12.9 kB

Total Files

9

Last publish

Collaborators

  • steveofficer