Can someone help me convert this code into a pointfree style?
To provide context: The function receives an Array of Either types and returns a Task type. If any of the Either types have the left set, the Task type is rejected with that value. If none of the Either types have the left set, the Task type is resolved. This function is used in the following way:
Async.parallel(xs).
map(eachToEither).
chain(rejectAnyLefts).
fork(error, success)
In practice, I would like to add another operation just before the `fork` to persist data. However, before doing so, I want to ensure that my code is as idiomatic as possible. The specific function in question here is `rejectAnyLefts`, which I am trying to write in a pointfree style but facing some challenges.
- The 'if' statement
- The requirement to store the leftObjs value for use in the 'if' condition and potentially the return value
const rejectAnyLefts = eitherArray => {
const leftObjs = r.filter(r.propEq("isLeft", true), eitherArray)
const isEmpty = r.propEq('length', 0)
return (isEmpty(leftObjs)) ?
Task.rejected(leftObjs) :
Task.of(eitherArray)
}