Skip to content

Spread operator (...) for arrays and dicts #1945

Description

@harehare

Description

Add a spread operator (...) to the mq language for expanding arrays and dicts inline within array literals and dict literals.

Proposed syntax

Array spread

let a = [1, 2, 3];
let b = [4, 5, 6];
let c = [...a, ...b];      # [1, 2, 3, 4, 5, 6]
let d = [0, ...a, 99];    # [0, 1, 2, 3, 99]

Dict spread

let base = {x: 1, y: 2};
let merged = {...base, y: 99, z: 3};   # {x: 1, y: 99, z: 3}

Later keys override earlier ones when the same key appears more than once.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    Status
    In progress

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions