Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
@skava/modules-modules / deps / transformWhereShape.ts
Size: Mime:
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 }