Skip to content

Conformance Examples 0.1.0 — Transforms: transform-first

first-list

Returns the first element of a list.

Template

{{ xs | first }}

Context

{
    "xs": [
        10,
        20,
        30
    ]
}

Output

10

first-empty-list-is-null

The first element of an empty list is null.

Template

{{ xs | first }}

Context

{
    "xs": []
}

Output

null

first-string

Liquid-compatible: the first character of a string.

Template

{{ s | first }}

Context

{
    "s": "hello"
}

Output

h

first-empty-string-is-null

The first character of an empty string is null.

Template

{{ s | first }}

Context

{
    "s": ""
}

Output

null

first-non-list-non-string-is-null

A numeric input is neither list nor string, so the result is null.

Template

{{ n | first }}

Context

{
    "n": 5
}

Output

null

first-struct-is-null

A struct input is neither list nor string, so the result is null.

Template

{{ o | first }}

Context

{
    "o": {
        "a": 1
    }
}

Output

null

Source fixture: transforms/transform-first.json