Skip to content

manual: point to the destructuring interface functions (rest, split_rest) from the Interfaces page #59611

@nsajko

Description

@nsajko

The doc strings are already in the Manual, but the Interfaces page does not mention them:

They should be added to the Interfaces page, as user-defined collection types might wish to add methods for performance.

Side note: there's another function that part of the destructuring interface, although it is not public: indexed_iterate. Perhaps it, too, should be public?

Example of the lowering of destructuring:

julia> function f(x)
           (a, b, c...) = x  # lowers using `rest`
           (m, n..., p, q) = c  # lowers using `split_rest`
           n
       end
f (generic function with 1 method)

julia> code_lowered(f)
1-element Vector{Core.CodeInfo}:
 CodeInfo(
1 ─ %1  =   dynamic Base.indexed_iterate(x, 1)
│         a = Core.getfield(%1, 1)
│         @_4 = Core.getfield(%1, 2)
│   %4  = @_4
│   %5  =   dynamic Base.indexed_iterate(x, 2, %4)
│         b = Core.getfield(%5, 1)
│         @_4 = Core.getfield(%5, 2)
│   %8  = @_4
│         c = Base.rest(x, %8)
│   %10 = c
│   %11 =   dynamic Base.indexed_iterate(%10, 1)
│         m = Core.getfield(%11, 1)
│         @_3 = Core.getfield(%11, 2)
│   %14 = c
│   %15 = @_3
│   %16 =   dynamic Base.split_rest(%14, 2, %15)
│         n = Core.getfield(%16, 1)
│   %18 =   builtin Core.getfield(%16, 2)
│   %19 =   dynamic Base.indexed_iterate(%18, 1)
│         p = Core.getfield(%19, 1)
│         @_3 = Core.getfield(%19, 2)
│   %22 = @_3
│   %23 =   dynamic Base.indexed_iterate(%18, 2, %22)
│         q = Core.getfield(%23, 1)
│   %25 = n
└──       return %25
)

Metadata

Metadata

Assignees

No one assigned

    Labels

    collectionsData structures holding multiple items, e.g. setsdocsThis change adds or pertains to documentationiterationInvolves iteration or the iteration protocol

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions