Squiggly

Collections

Operating on lists and maps — head, tail, slice, filter, map, set ops.

Squiggly’s collection builtins operate on Scala Seq[?] values (lists, vectors) and Map[?, ?] values. Anywhere a function takes a list, an Iterable works — strings are not iterables here, so collection-only ops (head, take, etc.) don’t apply to strings.

All builtins follow the data-last convention: in pipe form xs | head becomes head xs, xs | take 3 becomes take 3 xs.

Length & predicates

FunctionAritySignatureWhat
length1length xsElement count (also works on strings + maps)
isEmpty1isEmpty xsTrue iff the collection has zero elements
nonEmpty1nonEmpty xsTrue iff the collection has at least one element
contains2contains needle xsTrue iff xs contains needle (seq) or key (map)

Picking elements

FunctionAritySignatureWhat
head1head xsFirst element
last1last xsLast element
tail1tail xsAll but the first element

Slicing

FunctionAritySignatureWhat
take2take n xsFirst n elements
takeRight2takeRight n xsLast n elements
drop2drop n xsAll but the first n
dropRight2dropRight n xsAll but the last n
slice2/3slice from xs / slice from until xsHalf-open slice by index

Reshaping

FunctionAritySignatureWhat
reverse1reverse xsReverse the order (also works on strings)
distinct1distinct xsDrop duplicates, preserving original order
compact1compact xsDrop null and the empty-tuple () elements
flatten1flatten xsFlatten one level of nesting; scalars pass through
append2append elem xsAppend a single element to the right
prepend2prepend elem xsPrepend a single element to the left
join2join sep xsConcatenate string elements with sep

Functional

FunctionAritySignatureWhat
map2map `expr` xsTransform each element; expr is a non-strict expression with . bound to the element
filter2filter `pred` xsKeep elements where pred is truthy
filterNot2filterNot `pred` xsKeep elements where pred is falsy

The expr / pred arguments are wrapped in backticks so they evaluate lazily, per element. Inside the expression . refers to the current element.

Set operations

FunctionAritySignatureWhat
intersect2intersect a bElements in both a and b
union2union a bElements in either a or b (duplicates collapsed)
symdiff2symdiff a bSymmetric difference — in one but not both
complement2complement a bElements in a but not in b

Conversion

FunctionAritySignatureWhat
toSeq1toSeq itMaterialise any Iterable into a Seq
sum1sum xsSum the numeric elements

Examples

{{ .args | head }}                            first positional arg
{{ .args | tail | join ' ' }}                 drop first, rejoin

{{ for n <- .nums | distinct }}               unique elements
  {{ n }}
{{ end }}

{{ if .items | nonEmpty }}{{ end }}          guard against empty list

{{ .tags | append 'featured' | join ' ' }}    add a tag, render

{{ filter `.published` .posts | length }}     count published posts
{{ map `.title | upper` .pages }}             every title in caps

{{ slice 0 3 .posts }}                        first three

Maps

for k, v <- m iterates a map. Many of the list builtins above also work on maps — length m returns the entry count, isEmpty m checks for an empty map, contains 'key' m checks for a key.

To pluck a value by key, use […] indexing in expressions:

{{ .config['baseURL'] }}
{{ .frontmatter.tags }}        // dot syntax works for string keys

Search

Esc
to navigate to open Esc to close