Skip to content

Instantly share code, notes, and snippets.

@h1z3y3
Created January 23, 2022 09:42
Show Gist options
  • Save h1z3y3/ef25a3bc1e9f47e2c80db4957853c02c to your computer and use it in GitHub Desktop.
Save h1z3y3/ef25a3bc1e9f47e2c80db4957853c02c to your computer and use it in GitHub Desktop.
import "strings"
band: {
// hidden fiels
_selfIndexAlbums: ["", "II", "III", "IV"]
_namedAblums: [
"Houses of the Holy",
"Physical Graffiti",
"Presence",
"In Through the Out Door",
"Coda",
]
name: "Led Zeppelin"
// List comprehension
selfTitled: [
for i, I in _selfIndexAlbums {title: "\(name) \(I)"},
]
// nested list comprehension
allAlbums: [
for i, I in _selfIndexAlbums {title: "\(name) \(I)"},
for N in _namedAblums { title: "\(N)" }
]
Albums: {
for key, val in allAlbums {
"\(strings.TrimSpace(val.title))": {
pos: key,
artist: name,
title: strings.TrimSpace(val.title),
titleLen: len(val.title)
}
}
}
}
- list comprehension: `[ for key, val in iterable { ... } ]`. Notice you can leave the key off, and you just get the value.
- field comprehension: `[ for key, val in iterable { ... } ]`. We've interpolated a field name by calling a builtin, notice the surrounding quotes.
- string interpolation: `"\(<a cue expression)"`. These are based on Swift's string interpolation, and it's the only valid mechanism when you want to be JSON compatible.
- hidden fields: `_hidden: "I'm hidden"` which begin with an underscore. There are also hidden definitions (`_#`)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment