Repository URL to install this package:
|
Version:
1.3.0 ▾
|
import { path, lens, assocPath, set } from 'ramda'
import { makeShape, recurse, curry2 } from 'chain'
// @NOTE same as above, but handles shape evolving,
// @TODO remove
const transformWhereShape = curry2((shape, obj) => {
let transformed = obj
const shapeEvolver = makeShape(shape)
const traverseInstance = recurse(obj)
// traverseInstance.shouldNotPop = true
traverseInstance.forEach((x, key, traverser) => {
if (traverser.isRoot) return
const evolution = shapeEvolver(x, key)
// when we have an evolution, use it
if (evolution !== false) {
const setForPath = lens(path(traverser.path), assocPath(traverser.path))
transformed = set(setForPath, evolution, transformed)
// do not go any deeper
// traverser.skip()
}
})
return transformed
})
export { transformWhereShape }