Skip to content

Summer-of-YS🔗

Load and Compose your YAML Files

Probably the biggest problem people have with YAML is that everything has to be in one file. Things start off nice and clean, but as requirements grow, so do your files!

What if you could compose your YAML documents like you compose your code? Lots of small, single-purpose, possibly reusable files that you can load and compose together into the thing you need?

That's what YS is all about. As you know, YS is a functional language, and it has quite a few ways to load data (and code too, since Code is Data™!) from external sources.

Today we'll be looking at how to load things from disk files, including:

  • Other YS files
  • YAML files (YAML is YS)
  • JSON files (JSON is YAML)

You can also load things from CSV/TSV files, shell commands, databases, APIs, environment variables, and the web, but those are topics for another day.

YS YAML Documents

YAML files (aka YAML streams) can contain multiple "documents".

A YAML document is a top level mapping or sequence "node". Most YAML files contain a single document, but YAML files can contain multiple (or zero!) documents. New documents are started with a line of three dashes: ---.

YS can put these documents to all kinds of good use.

When you "load" a YAML file with YS, the result is the evaluation of the final document (by default). But since YS is functional, it can access any of the other documents.

Let's continue with yesterday's shoes example.

YAML Variables

YAML itself isn't a functional programming language, but advanced users are probably aware of YAML's anchors, aliases and the merge key.

The merge key is YAML's one functional thing, and it's actually not even part of the YAML 1.2 spec. However, people find it useful and many YAML implementations (including YS) support it.

The merge key (<<) is a special key that allows you to merge the contents of one mapping into another.

Today we'll explore the merge key a bit and show how variables can make it nicer to use.

The Summer of YS

Today starts a 3 month long, daily summertime journey into the intricacies of YAML and the wisdom of YS! Put on your favorite pair of coding sunglasses, grab a refreshing config drink, and let's get started!

Back in March I promised to start writing more often about all the ways that YS can help you out day-to-day with your YAML interactions. When I last posted here it was barely Spring and now Spring is turning into Summer.

Seasonal turning points be damned, I think of Summer as June, July, and August. In other words...

It's Summer dammit!

Let's declare this Summer, The Summer of YS!