
Company News
Socket Named Top Sales Organization by RepVue
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.
@iterables/sieve
Advanced tools
Sometimes you want to iterate over a set once and split the set into two separate usable piles.
This does that!
const sieve = require('@iterables/sieve')
const [yes, no] = sieve([1, 0, 1], (xs, idx, all) => {
return Boolean(xs)
})
console.log([...yes]) // [1, 1]
console.log([...no]) // [0]
// works with any iterable:
const [yes, no] = sieve(function * () {
yield 0
yield 1
yield 2
}(), xs => Boolean(xs))
console.log([...yes]) // [1, 2]
console.log([...no]) // [0]
$ npm install --save @iterables/sieve
sieve(iterable:Iterator<T>, test:Function) -> [Iterator<T>, Iterator<T>]iterable: any iterable (generator instance, Set, Map, Array, etc.)test: a function taking xs, idx, and all, returning Boolean
xs: an item from iterable.idx: the index within the array.all: the original iterableReturns a two-element array of iterators. The first element, yes, is an
iterable of all items from the original iterable that pass the test function.
The second element, no, contains all the failing items.
Note: this function will buffer the skipped items in the second iterable to be
realized. That is, if you evaluate the yes iterable all at once first, all
failing elements will be buffered in no until it is iterated. Usually realizing
the array is the goal, so keeping the elements in memory shouldn't be an issue.
If memory is an issue, consider taking one element at a time from yes and
no, which will buffer at most N items, where N is the largest run of
all-passing or all-failing items.
MIT
FAQs
split one iterable into two based on a test function
We found that @iterables/sieve demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Company News
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.

Security News
NIST will stop enriching most CVEs under a new risk-based model, narrowing the NVD's scope as vulnerability submissions continue to surge.

Company News
/Security News
Socket is an initial recipient of OpenAI's Cybersecurity Grant Program, which commits $10M in API credits to defenders securing open source software.