Skip to content

Read-only ES6 Map implementation that aggregates results from multiple Maps in O(n)

License

Notifications You must be signed in to change notification settings

felixfbecker/aggregate-map

Repository files navigation

Aggregate Map

npm downloads build codecov dependencies node code style: prettier semantic-release license

A read-only ES6 Map implementation that aggregates results from multiple Maps in O(n)

📖 API Documentation

Simple Example:

const maps = [new Map([['foo', 'bar']]), new Map([['baz', 'qux']])]

const aggregate = new AggregateMap(maps)

aggregate.get('baz') // 'qux'
aggregate.has('foo') // true

for (const [key, value] of aggregate) {
  console.log(key, value) // ['foo', 'bar'] ['baz', 'qux']
}

Advanced Example:

import iterate from 'iterare'

class Repository {
  public pullRequests: ReadonlyMap<string, PullRequest> = new AggregateMap({
    [Symbol.iterator]: () => iterate(this.remotes).map(remote => remote.pullRequests),
  })
  private remotes = new Map<string, RepositoryRemote>()
}

class RepositoryRemote {
  public pullRequests = new Map<string, PullRequest>()
}

About

Read-only ES6 Map implementation that aggregates results from multiple Maps in O(n)

Resources

License

Stars

Watchers

Forks

Packages