rambda
Version:
Lightweight and faster alternative to Ramda with included TS definitions
32 lines (25 loc) • 640 B
JavaScript
import { curry } from './curry.js'
function mergeWithFn(
mergeFn, aInput, bInput
){
const a = aInput ?? {}
const b = bInput ?? {}
const willReturn = {}
Object.keys(a).forEach(key => {
if (b[ key ] === undefined){
willReturn[ key ] = a[ key ]
} else {
willReturn[ key ] = mergeFn(a[ key ], b[ key ])
}
})
Object.keys(b).forEach(key => {
if (willReturn[ key ] !== undefined) return
if (a[ key ] === undefined){
willReturn[ key ] = b[ key ]
} else {
willReturn[ key ] = mergeFn(a[ key ], b[ key ])
}
})
return willReturn
}
export const mergeWith = curry(mergeWithFn)