So lets say I had a chained sequence like the following:
let amount = _
.chain(selectedItemsArray)
.map(item => _.find(availableItems, {id: item.id})
//how can I determine that ALL items were found right here?
.filter('price_money')
...
Note the comment in the code above. It could be possible that the selectedItemsArray
is out of date, so some selected items might not be in availableItems
. So, my initial thought was to use a .tap
or .thru
(probably tap) to do something like _.every(selectedItems, _.isObject)
or something similar to catch the error state where not all items are found and throw an error if not all items were found. This feels odd though...any better ways of handling this type of error checking mid sequence?
Something like this does work (at least I can throw an error), but seems like I'm using tap
for something it's not intended for:
.tap(items => {
if (!_.every(items, _.isObject)) throw new Error('Some selected items are no longer available');
})