npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@metarhia/iterator

v1.0.0-alpha3

Published

Efficient and composable iteration

Downloads

172

Readme

@metarhia/iterator - efficient and composable iteration

CI Status Badge

Installation

$ npm install @metarhia/iterator

API

class Iterator

Iterator.range(start, stop[, step])

Returns: <Iterator>

Create iterator iterating over the range

Iterator.zip(...iterators)

Returns: <Iterator>

Create iterator by zipping multiple provided iterators into one

Iterator.prototype.constructor(base)

Iterator.prototype.apply(fn)

Returns: the result of fn(this) call.

Call a function with this. Will be equivalent to calling fn(it).

Iterator.prototype.chain(...iterators)

Iterator.prototype.chainApply(fn)

Returns: <Iterator> result of fn(this) wrapped in an Iterator.

Call a function with this and wrap the result in an Iterator.

Example:

iter([1, 2])
  .chainApply(([a, b]) => [a + b, a - b])
  .join(', ');

Result:

'3, -1';

Iterator.prototype.collectTo(CollectionClass)

Iterator.prototype.collectWith(obj, collector)

Iterator.prototype.count()

Iterator.prototype.each(fn, thisArg)

Iterator.prototype.enumerate()

Iterator.prototype.every(predicate, thisArg)

Iterator.prototype.filter(predicate, thisArg)

Iterator.prototype.filterMap(mapper[, thisArg[, filterValue]])

  • mapper: <Function> function that maps values and returns either new value that will be the next value of the new iterator or filterValue that will be ignored.
    • value: <any> iterator element
  • thisArg: <any> value to be used as this when calling mapper
  • filterValue: <any> value to filter out mapper results.

Creates an iterator that both filters and maps with the passed mapper.

This iterator will call mapper on each element and if mapper returns NOT filterValue it will be returned, otherwise it is ignored.

Iterator.prototype.find(predicate, thisArg)

Iterator.prototype.findCompare(comparator[, accessor[, thisArg]])

  • comparator: <Function> returns true if new value should be accepted
    • currValue: <any> current value, starts with undefined
    • nextValue: <any> next value
    • Returns: <boolean> true if next value should be accepted
  • accessor: <Function> gets value to compare by, current iterator value is used by default
    • value: <any> current iterator value
    • Returns: <any> value to compare by
  • thisArg: <any> value to be used as this when calling accessor and comparator

Returns: last iterator value where comparator returned true, <undefined> by default

Find value in this iterator by comparing every value with

the found one using comparator

Iterator.prototype.flat(depth = 1)

Iterator.prototype.flatMap(mapper, thisArg)

Iterator.prototype.forEach(fn, thisArg)

Iterator.prototype.groupBy(classifier[, thisArg])

  • classifier: <Function> gets value to group by
    • value: <any> current iterator value
    • Returns: <any> value to group by
  • thisArg: <any> value to be used as this when calling classifier
  • Returns: <Map> map with arrays of iterator values grouped by keys returned by classifier

Consumes an iterator grouping values by keys

Iterator.prototype.includes(element)

Iterator.prototype.join(sep = ', ', prefix = '', suffix = '')

Iterator.prototype.map(mapper, thisArg)

Iterator.prototype.max([accessor[, thisArg]])

  • accessor: <Function> gets value to compare by, current iterator value is used by default
    • value: <any> current iterator value
    • Returns: <any> value to compare by
  • thisArg: <any> value to be used as this when calling accessor

Returns: element with maximum value or <undefined> if iterator is empty

Find the maximum value in this iterator

Iterator.prototype.min([accessor[, thisArg]])

  • accessor: <Function> gets value to compare by, current iterator value is used by default
    • value: <any> current iterator value
    • Returns: <any> value to compare by
  • thisArg: <any> value to be used as this when calling accessor

Returns: element with minimum value or <undefined> if iterator is empty

Find the minimum value in this iterator

Iterator.prototype.next()

Iterator.prototype.partition(predicate[, thisArg])

  • predicate: <Function> function returns a value to partition this iterator
    • value: <any> current iterator element
    • Returns: <boolean>|<number> key denoting resulting partition this value will be assigned to. Number denotes index in the resulting array. Boolean will be cast to number
  • thisArg: <any> value to be used as this when calling predicate
  • Returns: <Array> array of partitions (arrays), will always have at least 2 arrays in it

Consumes an iterator, partitioning it into Arrays

Iterator.prototype.reduce(reducer, initialValue)

Iterator.prototype.skip(amount)

Iterator.prototype.skipWhile(predicate, thisArg)

Iterator.prototype.some(predicate, thisArg)

Iterator.prototype.someCount(predicate, count, thisArg)

Iterator.prototype.take(amount)

Iterator.prototype.takeWhile(predicate, thisArg)

Iterator.prototype.toArray()

Iterator.prototype.toObject()

Transforms an iterator of key-value pairs into an object.

This is similar to what {Object.fromEntries()} would offer.

Iterator.prototype.zip(...iterators)

iter(base)

iterEntries(obj)

iterKeys(obj)

iterValues(obj)

class AsyncIterator

AsyncIterator.prototype.constructor(base)

AsyncIterator.prototype.chain(...iterators)

async AsyncIterator.prototype.collectTo(CollectionClass)

async AsyncIterator.prototype.collectWith(obj, collector)

async AsyncIterator.prototype.count()

async AsyncIterator.prototype.each(fn, thisArg)

AsyncIterator.prototype.enumerate()

async AsyncIterator.prototype.every(predicate, thisArg)

AsyncIterator.prototype.filter(predicate, thisArg)

async AsyncIterator.prototype.find(predicate, thisArg)

AsyncIterator.prototype.flat(depth = 1)

AsyncIterator.prototype.flatMap(mapper, thisArg)

async AsyncIterator.prototype.forEach(fn, thisArg)

async AsyncIterator.prototype.includes(element)

async AsyncIterator.prototype.join(sep = ', ', prefix = '', suffix = '')

AsyncIterator.prototype.map(mapper, thisArg)

async AsyncIterator.prototype.next()

async AsyncIterator.prototype.parallel(fn, thisArg)

async AsyncIterator.prototype.reduce(reducer, initialValue)

AsyncIterator.prototype.skip(amount)

async AsyncIterator.prototype.some(predicate, thisArg)

async AsyncIterator.prototype.someCount(predicate, count, thisArg)

AsyncIterator.prototype.take(amount)

AsyncIterator.prototype.takeWhile(predicate, thisArg)

AsyncIterator.prototype.throttle(percent, min)

async AsyncIterator.prototype.toArray()

AsyncIterator.prototype.zip(...iterators)

asyncIter(base)

  • base: <Iterable>|<AsyncIterable> an iterable that is wrapped in <AsyncIterator>

Returns: <AsyncIterator>

Create an AsyncIterator instance

Contributors

See github for full contributors list