Skip to content

Adding comparison/hashing to Base.Some #35911

@schlichtanders

Description

@schlichtanders

Dear Julia community,

what started as a short discourse discussion I would like to rephrase as a change request.

Currently, Base.Some is treated like Ref in that Some([]) != Some([]), unlike Vector for instance. However in other programming languages, Some actually behaves more like Vector in the sense that it is paired with Nothing and in this combination represents a Container of either one or zero elements.

For instance in Scala Some(List()) == Some(List()).

For consistency with the general semantics of Some/Option/Optional/Maybe (or however it might be called in other programming languages), I would plead for adding the following two lines to Base

Base.:(==)(a::Some, b::Some) = a.value == b.value
Base.hash(a::Some) = hash(a.value)

This is a breaking change.

Metadata

Metadata

Assignees

No one assigned

    Labels

    equalityIssues relating to equality relations: ==, ===, isequalfeatureIndicates new feature / enhancement requestshashing

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions