🚀 Feature Request
It would be nice if there were a .filterMap(...) on arbitraries.
Motivation
Sometimes I find that I need to do some mapping in .map(...), but the mapping is fallible because it's not trivial to represent all the necessary preconditions in the source arbitrary.
In that case, I end up needing to extract the precondition checks to a .filter(...), but that's annoying because it forces me to split the logic, which often results in duplicative work between the .filter(...) and .map(...).
It would be nice if I could use a .filterMap(...) and return the mapped value or null (or maybe a better API would be some Result<T> return type, so that null is an allowed mapped values).
Example
arb.filterMap(value => {
const transformedValue = transform(value)
if (someFancyCondition(transformedValue)) {
return { ok: true, value: transformedValue }
}
return { ok: false }
})
🚀 Feature Request
It would be nice if there were a
.filterMap(...)on arbitraries.Motivation
Sometimes I find that I need to do some mapping in
.map(...), but the mapping is fallible because it's not trivial to represent all the necessary preconditions in the source arbitrary.In that case, I end up needing to extract the precondition checks to a
.filter(...), but that's annoying because it forces me to split the logic, which often results in duplicative work between the.filter(...)and.map(...).It would be nice if I could use a
.filterMap(...)and return the mapped value or null (or maybe a better API would be someResult<T>return type, so thatnullis an allowed mapped values).Example