Record.mergeWith (using Ord)
Adapts lodash's mergeWith using fp-ts idioms & type safety
import * as S from "fp-ts/string";
const test = mergeWith(
{ a: { b: 'hello' } },
{ a: { b: ' world', c: 123 }, e: false },
{ a: { b: S.Semigroup } }
)
/* test = {
a: {
b: "hello world",
c: 123
},
e: false
} */
runnable implementation (playground)
maybe a good candidate for a 'Struct' module, as per https://github.com/samhh/fp-ts-std/issues/110?
Deeply merging makes me nervous knowing TypeScript.
I wonder if there might be value in a PartialSemigroup typeclass. It'd be bridging the same gap but potentially in a more general way. The desired function would be provided by concat itself.
If Semigroup is a binary operation on A, PartialSemigroup would need to operate over an A and a Partial<A>? You lose deep merging.
Though that then makes me question why A isn't using Options at which point it could just use Semigroup. :wink: