Fortunately, JavaScript has the resources to deal with its lack of laziness. Thus, it is completely possible to declare a recursive solution from zero point using lambda functions as follows: a => f(a) . Just replace R.map(removeNull) with R.map(a =>removeNull(a)) .
const removeNulls = R.ifElse( R.either(R.is(Array), R.is(Object)), R.pipe( R.filter(R.pipe(R.isNil, R.not)), R.map(a => removeNulls(a)) ), R.identity )
In your case, I recommend using R.reject , which is an oposite for R.filter . Since you deny the predicate, R.filter(R.pipe(R.isNil, R.not)) is equal to R.reject(R.isNil)
const removeNulls = R.ifElse( R.either(R.is(Array), R.is(Object)), R.pipe( R.reject(R.isNil), R.map(a => removeNulls(a)) ), R.identity )
Finally, this function has the following ifElse(predicate, whenTrue, identity) structure, which is equal to when(predicate, whenTrue)
const removeNulls = R.when( R.either(R.is(Array), R.is(Object)), R.pipe( R.reject(R.isNil), R.map(a => removeNulls(a)) ) )
source share