Skip to content

A more user-friendly function enhancing the push!(S::Set, element) method? #59084

@WalterMadelim

Description

@WalterMadelim

Currently the push! function returns the updated S

julia> S = Set();

julia> push!(S, 1)
Set{Any} with 1 element:
  1

The returned object is uninformative to a user, since when I need S I can call it out directly

julia> S
Set{Any} with 1 element:
  1

Therefore I think devising a new function achieving the following is more meaningful in practice (I guess the implementation can be optimized, thereby opening this issue)

collect!(S, e) = e in S ? false : (push!(S, e); true)

A detailed discussion is at https://discourse.julialang.org/t/receive-the-success-status-of-push-set-element/130988?u=waltermadelim

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