Skip to content

Clarify list pattern behavior in documentation #163

@panpanpro888

Description

@panpanpro888

I was reading the Gleam language overview on list patterns and it's not clear that you can store the matched values in variables. While this is seen 3 sections below on the list recursion section, its main point is not to show how list patterns function, so I think it would be nice to have it in the documentation. Something like:

You can also store these values in variables. [first, second, ..rest] will match the first two values in first and second respectively and the rest in rest

And in the examples:

import gleam/string
import gleam/int
import gleam/list

[3] -> "List of just 3"
[3, ..rest] -> "List starting with 3 and the rest being: " <> rest |> list.map(fn(n) { int.to_string(n) }) |> string.join(", ")

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions