Skip to content

proposal: cmp: Equal #70161

@jimmyfrasche

Description

@jimmyfrasche

Proposal Details

I find myself writing this a lot lately. Sometimes multiple times in a module because I don't want to export it or bother with creating internal/ packages just for this.

package cmp

func Equal[T comparable](a, b T) bool {
  return a == b
}

This comes up whenever you have Op and OpFunc where the latter variant takes an equality function. The body of Op just calls OpFunc with some local copy of the proposed.

Even with the shortest possible syntax proposed in #21498 this would still be (a, b) => a == b vs cmp.Equal[T] and T would often be inferred as this is basically always used as the argument to a function.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions