-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
29 lines (26 loc) · 935 Bytes
/
index.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
import reduceValues from "@unction/reducevalues"
import replaceWhen from "@unction/replacewhen"
import isNil from "@unction/isnil"
import dig from "@unction/dig"
import type {ArrayType} from "types"
import type {UnfinishedKeyChainType} from "types"
import type {UnaryFunctionType} from "types"
import type {KeyedEnumerableType} from "types"
import type {ValueType} from "types"
import type {KeyChainType} from "types"
export default function cascadingKeyChain (keychains: ArrayType<UnfinishedKeyChainType>): UnaryFunctionType {
return function cascadingKeyChainChains (tree: KeyedEnumerableType): ValueType {
return reduceValues(
(filler: ValueType | null): UnaryFunctionType => (keychain: KeyChainType): ValueType => {
if (isNil(filler)) {
return dig(keychain)(tree)
}
return dig(replaceWhen(isNil)(filler)(keychain))(tree)
}
)(
null
)(
keychains
)
}
}