Skip to content

Conformance Examples 0.1.0 — Transforms: transform-last

last-list

Returns the last element of a list.

Template

{{ xs | last }}

Context

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

Output

30

last-empty-list-is-null

The last element of an empty list is null.

Template

{{ xs | last }}

Context

{
    "xs": []
}

Output

null

last-string

Liquid-compatible: the last character of a string.

Template

{{ s | last }}

Context

{
    "s": "hello"
}

Output

o

last-non-list-non-string-is-null

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

Template

{{ n | last }}

Context

{
    "n": 5
}

Output

null

last-struct-is-null

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

Template

{{ o | last }}

Context

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

Output

null

Source fixture: transforms/transform-last.json