Skip to content

Sum with init doesn't work for empty iterable #39669

@aplavin

Description

@aplavin

Documentation for sum says that The value returned for empty itr can be specified by init.. However, sum(i for i in 1:0, init=0) throws an error: ArgumentError: reducing over an empty collection is not allowed.
Same with sum(identity, i for i in 1:0, init=0).
This happens on both 1.6 and nightly. As I understand, empty collections were the whole point of introducing init= argument, is it just not implemented yet?

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