Skip to content

default parameter for array.join #6891

@MDLC01

Description

@MDLC01

Description

Currently, calling array.join on an empty array returns none. There should be a default argument, similar to the one on array.sum or array.product, defining the value to return for an empty array (defaulting to none).

Use Case

It is easier to write arr.join(", ", default: "") than

#if arr.len() == 0 {
  ""
} else {
  arr.join(", ")
}

Drawbacks

As mentioned in #6780 (comment), the proliferation of default arguments may indicate than a more general solution should be implemented. In the meantime, this proposal makes sense.

Metadata

Metadata

Assignees

No one assigned

    Labels

    change requestA proposal for changes to an existing featurescriptingAbout Typst's coding capabilities

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions