deno.land / x / rambda@v9.1.1 / source / modifyPath.js

نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import { createPath } from './_internals/createPath.js'import { isArray } from './_internals/isArray.js'import { assoc } from './assoc.js'import { curry } from './curry.js'import { path as pathModule } from './path.js'
export function modifyPathFn( pathInput, fn, object){ const path = createPath(pathInput) if (path.length === 1){ return { ...object, [ path[ 0 ] ] : fn(object[ path[ 0 ] ]), } } if (pathModule(path, object) === undefined) return object
const val = modifyPath( Array.prototype.slice.call(path, 1), fn, object[ path[ 0 ] ] ) if (val === object[ path[ 0 ] ]){ return object }
return assoc( path[ 0 ], val, object )}
export const modifyPath = curry(modifyPathFn)
rambda

Version Info

Tagged at
2 months ago