This returns a deep map-based tree that has the indicated value for any requested leaf node.
// constant.ori
Tree.constant(1)
This always returns the value 1 for any path to a leaf node:
$ 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
Tree.deepMerge(
Tree.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