Add string concatenation to YAML via user-defined tag !join

Wouldn’t it be neat to add string concatenation to YAML in homeassistant to simplify configuration writing? Thus:

user_directory: /home/user/me
user_pictures: /home/user/me/pictures
user_videos: /home/user/me/videos

would be simplified in:

user_directory: &DIR /home/user/me
user_pictures: !join [*DIR, /pictures]
user_videos: !join [*DIR, /videos]

Obviously, the more a constant string gets reused, the more advantageous this writing gets to be!

The possibility to do so and the way to implement it is taken from Chris Johnson discussion on StackOverflow:

Fortunately there’s a simple way to add string concatenation to YAML via user-defined tags

User-defined tags is a standard YAML capability - the YAML 1.2 spec says YAML schemas allow the “use of arbitrary explicit tags”. Handlers for those custom tags need to be implemented in a custom way in each language you’re targeting. Doing that in Python looks like this:

## in your python code

import yaml

## define custom tag handler
def join(loader, node):
    seq = loader.construct_sequence(node)
    return ''.join([str(i) for i in seq])

## register the tag handler
yaml.add_constructor('!join', join)

In home assistant core, only file /homeassistant/util/yaml/loader.py would have to be modified to implement such a feature. Would this feature be acceptable?

YAML anchors already exist and can be used…
Not exactly what you are asking for, but already exists and sort of related in function.

https://www.linode.com/docs/guides/yaml-anchors-aliases-overrides-extensions/.

YAML anchors | Bitbucket Cloud | Atlassian Support.

Indeed YAML anchors already exist and can be used in such a way:

user_dir: &user_home /home/user
user_pics: *user_home

However concatenation doesn’t exist natively in YAML, so this won’t work:

user_dir: &user_home /home/user
user_pics: *user_home/pics

!join, as described in my previous post, is supposed to remedy this:

user_dir: &user_home /home/user
user_pics: !join [*user_home, /pics]

I hope I was more clear with those explanations.