krisk / Fuse

Lightweight fuzzy-search, in JavaScript
https://fusejs.io/
Apache License 2.0
18.2k stars 768 forks source link

Add remove function with predicate #439

Closed krisk closed 4 years ago

krisk commented 4 years ago

Description

Add API which removes all documents from the list which the predicate returns truthy for, and returns an array of the removed docs.

Describe the solution you'd like

The predicate is invoked with two arguments: (doc, index)

remove(predicate: (doc: T, idx: number) => boolean): T[]

Thus you can use it as such:

fuse.remove((doc) => {
  return doc === 'banana' || doc === 'pear'
})

Describe alternatives you've considered

You'd have to know the index, and use the removeAt function instead.

krisk commented 4 years ago

Now in latest fuse.js@6.2.0