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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
// Replaces items of a list, which are null or undefined, with some fallback
// value. By default, this replaces the passed dependency.
//
// See also:
// - excludeFromList
//
// More list utilities:
// - withFlattenedList
// - withPropertyFromList
// - withPropertiesFromList
// - withUnflattenedList
//
import {input, templateCompositeFrom} from '#composite';
export default templateCompositeFrom({
annotation: `fillMissingListItems`,
inputs: {
list: input({type: 'array'}),
fill: input({acceptsNull: true}),
},
outputs: ({
[input.staticDependency('list')]: list,
}) => [list ?? '#list'],
steps: () => [
{
dependencies: [input('list'), input('fill')],
compute: (continuation, {
[input('list')]: list,
[input('fill')]: fill,
}) => continuation({
['#filled']:
list.map(item => item ?? fill),
}),
},
{
dependencies: [input.staticDependency('list'), '#filled'],
compute: (continuation, {
[input.staticDependency('list')]: list,
['#filled']: filled,
}) => continuation({
[list ?? '#list']:
filled,
}),
},
],
});
|