eucalypt · functional data language
A little language for YAML, JSON and TOML.
Generate, template and transform structured data with a lazy, functional language and a command-line tool that reads and writes the formats you already use.
brew install curvelogic/homebrew-tap/eucalyptEvery output in this editor was produced by the eu engine when the page was built.
service(overrides): {
name: "ledger"
replicas: 2
db: { host: "db.internal" port: 5432 pool: 10 }
} << overrides
staging: service{ db: { host: "db.staging" } }
production: service{ replicas: 6 db: { pool: 40 } }---
staging:
name: ledger
replicas: 2
db:
host: db.staging
port: 5432
pool: 10
production:
name: ledger
replicas: 6
db:
host: db.internal
port: 5432
pool: 40{
"production": {
"db": {
"host": "db.internal",
"pool": 40,
"port": 5432
},
"name": "ledger",
"replicas": 6
},
"staging": {
"db": {
"host": "db.staging",
"pool": 10,
"port": 5432
},
"name": "ledger",
"replicas": 2
}
}[staging]
name = "ledger"
replicas = 2
[staging.db]
host = "db.staging"
port = 5432
pool = 10
[production]
name = "ledger"
replicas = 6
[production.db]
host = "db.internal"
port = 5432
pool = 40` :suppress
people: [
{ name: "ada" team: :core score: 92 },
{ name: "brendan" team: :web score: 71 },
{ name: "grace" team: :core score: 88 }
]
leaders: people filter(_.score > 80) map(_.name str.to-upper)---
leaders:
- ADA
- GRACE{
"leaders": [
"ADA",
"GRACE"
]
}leaders = ["ADA", "GRACE"]service(n): {
name: "web-{n}"
port: 8080 + n
tier: (n = 0) then(:primary, :replica)
}
services: range(0, 3) map(service)---
services:
- name: web-0
port: 8080
tier: primary
- name: web-1
port: 8081
tier: replica
- name: web-2
port: 8082
tier: replica{
"services": [
{
"name": "web-0",
"port": 8080,
"tier": "primary"
},
{
"name": "web-1",
"port": 8081,
"tier": "replica"
},
{
"name": "web-2",
"port": 8082,
"tier": "replica"
}
]
}[[services]]
name = "web-0"
port = 8080
tier = "primary"
[[services]]
name = "web-1"
port = 8081
tier = "replica"
[[services]]
name = "web-2"
port = 8082
tier = "replica"ports: { http: 80 https: 443 }
# One of these keys is misspelt: the error says which.
open: [ports.http, ports.htps]error: key 'htps' not found in block help: similar keys: 'https', 'http' ┌─ ports.eu:4:20 │ 4 │ open: [ports.http, ports.htps] │ ^^^^^
user: { name: "ada" id: 7 }
greeting: "Hello, {user.name}! You are user #{user.id:%03d}."---
user:
name: ada
id: 7
greeting: "Hello, ada! You are user #007."{
"greeting": "Hello, ada! You are user #007.",
"user": {
"id": 7,
"name": "ada"
}
}greeting = "Hello, ada! You are user #007."
[user]
name = "ada"
id = 7` "An infinite list, evaluated only as far as it is needed."
powers: iterate(* 2, 1) take(8)---
powers:
- 1
- 2
- 4
- 8
- 16
- 32
- 64
- 128{
"powers": [
1,
2,
4,
8,
16,
32,
64,
128
]
}powers = [1, 2, 4, 8, 16, 32, 64, 128]It speaks your formats
Reads what you have. Writes what you need.
YAML, JSON, JSON Lines, TOML, EDN, XML, CSV and text in; YAML, JSON, TOML, EDN, HTML, text and eucalypt itself out. Mix them on one command line.
Embedded in YAML
Tag a value with !eu and keep the rest of the file as it is.
region: eu-west-1
buckets: !eu '["logs", "assets"] map("{region}-{}")'region: eu-west-1
buckets:
- eu-west-1-logs
- eu-west-1-assetsCSV in, totals out
Import a file as a named input and process it like any other data.
name,team,hours
ada,core,38
brendan,web,22
grace,core,41{ import: "rows=staff.csv" }
hours: rows group-by(_.team) map-values(map(_.hours num) ; sum)hours:
core: 79
web: 22A one-liner in the shell
Query structured data without writing a file. Here, JSON out with -j.
$ eu -j rows=staff.csv -e 'rows filter(_.team = "core") map(.name)'[
"ada",
"grace"
]Why eucalypt
Three things it is, and what each one means.
Data-native
Blocks are mappings and lists are lists. You build the data structure itself, so there is no indentation to template and no quoting to escape.
[staging]
name = "ledger"
replicas = 2Lazy and functional
Nothing is evaluated until the output needs it, so infinite lists and unused branches cost nothing.
` "An infinite list, evaluated only as far as it is needed."
powers: iterate(* 2, 1) take(8)powers = [1, 2, 4, 8, 16, 32, 64, 128]Gradually typed
Annotate where it helps. The checker warns without stopping evaluation, unless you pass --strict.
` { type: "number -> string" }
port-label(n): "port {n}"
label: port-label("8080")warning: type mismatch calling 'port-label'
┌─ types.eu:4:19
│
4 │ label: port-label("8080")
│ ^^^^^^ expected number, found "8080"A short tour
Six ideas, each a line or two long.
Every snippet runs. Open one in the playground to change it.
Anaphora_0, {}
squares: [1, 2, 3, 4] map(_0 * _0)
labels: [:a, :b] map("item-{}")squares:
- 1
- 4
- 9
- 16
labels:
- item-a
- item-bInterpolation"{x:%03d}"
user: { name: "ada" id: 7 }
greeting: "Hello, {user.name}! You are user #{user.id:%03d}."user:
name: ada
id: 7
greeting: "Hello, ada! You are user #007."Deep merge<<
merged: { db: { host: "localhost" port: 5432 } }
<< { db: { host: "db.prod" } }merged:
db:
host: db.prod
port: 5432Inline tests//=>
slug(s): s str.to-lower str.replace(" +", "-")
title: "Hello Gum Trees" slug //=> "hello-gum-trees"title: hello-gum-treesGet started
Install it, then point your editor at it.
brew install curvelogic/homebrew-tap/eucalyptcurl -sSf https://raw.githubusercontent.com/curvelogic/eucalypt/master/install.sh | shcargo install --path .Editor support
The eucalypt extension starts the language server for you.
eucalypt-mode, with eglot for the language server.
eu lsp speaks the Language Server Protocol over stdio.Learn