Returns the first value in the tree. This can be useful in the CLI to quickly inspect a sample value from a tree.
For example, if a data pipeline processes content into data ready for templating, first
can be used to check that the data coming out of the pipeline is correct. If the data is an array, then a normal array index like [0]
can be used to view a specific value. But if the data is another kind of object, you can use first
to pick out a single value that may represent the rest.
This data file has string keys:
# movies.yaml
kiki:
title: Kiki's Delivery Service
year: 1989
mononoke:
title: Princess Mononoke
year: 1997
spirited:
title: Spirited Away
year: 2001
heron:
title: The Boy and the Heron
year: 2023
You can extract the first value with:
$ ori Tree.first movies.yaml
title: Kiki's Delivery Service
year: 1989