Skip to content

Commit

Permalink
.findWhere()
Browse files Browse the repository at this point in the history
  • Loading branch information
micheletriaca committed Sep 19, 2021
1 parent 76c54d9 commit c472db1
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/index.js
Expand Up @@ -54,4 +54,5 @@ _.extend('toArray', function (fn) { return _.toArray(fn, this) })
_.extend('toPromise', function () { return _.toPromise(this) })
_.extend('toNodeStream', function (options) { return _.toNodeStream(options, this) })
_.extend('where', function (props) { return _.where(props, this) })
_.extend('findWhere', function (props) { return _.findWhere(props, this) })
_.extend('ratelimit', function (num, ms) { return _.ratelimit(num, ms, this) })
2 changes: 2 additions & 0 deletions src/methods.js
Expand Up @@ -97,6 +97,8 @@ _m.where = _.curry((props, s) => s.filter(x => {
return true
}))

_m.findWhere = _.curry((props, s) => s.where(props).take(1))

_m.ratelimit = _.curry((num, ms, s) => {
let sent = 0
let startWindow
Expand Down
1 change: 1 addition & 0 deletions test/errors.test.js
Expand Up @@ -330,6 +330,7 @@ test('error propagation', async () => {
.csvStringify()
.head()
.last()
.findWhere()
.resolve()
.slice(1, 3)
.makeAsync(10)
Expand Down
7 changes: 7 additions & 0 deletions test/exstream.test.js
Expand Up @@ -747,6 +747,13 @@ test('where', () => {
expect(res).toEqual([{ a: 'a', b: 'b' }])
})

test('findWhere', () => {
const res = _([{ a: 'a', b: 'b' }, { a: 'b', b: 'c' }, { a: 'a', b: 'b' }])
.findWhere({ a: 'a' })
.value()
expect(res).toEqual({ a: 'a', b: 'b' })
})

test('multipipe', () => new Promise(resolve => {
// This demonstrates how to pipe multiple input streams into an exstream writer. You can even control parallelism
// and order. The whole chain has back-pressure
Expand Down

0 comments on commit c472db1

Please sign in to comment.