This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const recMerge = (objA, objB) => Object.entries(objB).reduce( | |
(acc, [key, val]) => Object.assign( | |
{}, | |
objA, | |
{ [key]: is(Object, val) ? recMerge(objA[key], val) : val } | |
), | |
{} | |
); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Predicate<T> = (value: T) => boolean; | |
type Mapper<T, R> = (value: T) => R; | |
type CondPair<T, R> = [Predicate<T>, Mapper<T, R>]; | |
// recursive cond that can breaks early or returns undefined | |
const cond = <T, R>( | |
[[pred, mapr] = [] as unknown as CondPair<T, R>, ...rest]: CondPair<T, R>[] = [] | |
): ((val: T) => R | undefined) => (val: T): R | undefined => | |
!pred ? undefined : | |
pred(val) ? mapr(val) : cond(rest)(val); |
OlderNewer