@supercharge/collections
Advanced tools
Changelog
3.0.0 - 2020-09-03
2.x
, you had to await every collection pipeline3.0
: all collections are sync by defaultcollection.all()
to retrieve the resulting array from a synchronous collectionmap
, filter
, find
, and so on:main
entrypoint in package.json
to dist
folderindex.js
file which acted as a middleman to export from dist
folderSynchronous collections work like JavaScript’s Array methods. For example, the following pipeline stays a synchronous pipeline:
const Collect = require('@supercharge/collections')
const collection = Collect([1, 2, 3, 4, 5])
.map(item => item * 2)
.filter(item => item > 5)
.sort((a, b) => b -a)
// on sync collections, you must explicitly call `.all()` to retrieve the result
const result = collection.all()
// [10, 8, 6]
In comparison, a collection becomes async as soon as you provide an async callback method to methods like map
, filter
, find
, and so on:
const Collect = require('@supercharge/collections')
const collection = Collect([1, 2, 3, 4, 5])
.map(async item => item * 2) // the collection is async from here on
.filter(item => item > 5)
.sort((a, b) => b -a)
// async collections must be awaited
const result = await collection
// [10, 8, 6]