This returns a deep tree that returns the indicated value
for any path.
// constant.ori
constant(1)
This always returns the value 1 for any path:
$ ori constant.ori/a
1
$ ori constant.ori/b
1
$ ori constant.ori/a/b/c
1
Set a default value
One use for constant
is to define a default value for a tree using tree:deepMerge
.
// deepDefault.ori
deepMerge(
constant(0) // Default value is zero
{
a: 1
b: {
c: 2
}
}
)
This provides the default value of zero for any level of the tree:
$ ori deepDefault.ori/a
1
$ ori deepDefault.ori/x
0
$ ori deepDefault.ori/b/c
2
$ ori deepDefault.ori/b/y
0