npm.io
1.0.4 • Published 2 years ago

nice-loops

Licence
ISC
Version
1.0.4
Deps
0
Size
75 kB
Vulns
0
Weekly
0

nice-loops

A spin on common Array methods like forEach, map, reduce, that periodically yield to the event loop

Implemented

  • forEach
  • map
  • reduce
  • find
  • some
  • every

Ending Iteration

Unlike in regular JavaScript, all iterations can be terminated early. In the callback function, returning the EndIteration symbol will stop iteration. At the moment you'll need to read the source to see what gets returned.

import { map, symbol } from "nice-loops"

await map([1, 2, 3, 4, 5], (n => (n < 3) ? (n * 2) : symbol.EndIteration) //=> [2, 4]