0.0.5 • Published 9 days ago

slothfuliter v0.0.5

Weekly downloads
-
License
MIT
Repository
github
Last release
9 days ago

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))
0.0.5

9 days ago

0.0.4

11 months ago

0.0.3

11 months ago

0.0.2

11 months ago

0.0.1

11 months ago