Coder Social home page Coder Social logo

Comments (8)

fasaxc avatar fasaxc commented on August 19, 2024 2

I found this while trying to make project calico's Set generic (PR) looking for a workaround for the "any not comparable" problem. The solution I happened on was to make an interface type Set[T any] and then two concrete implementations: type mapSet[T comparable] map[T]struct{} and type boxedSet[T any] map[any]struct{}. Then you can use mapSet if possible and boxedSet for interface types.

They both give type-safe methods πŸ‘ but boxedSet has the overhead of boxing/unboxing into an any. They both implement Set[T] once T is specified so apart from picking the right constructor they're interchangable after that.

from golang-set.

deckarep avatar deckarep commented on August 19, 2024 1

Hey thanks for the vote of confidence on the new changes as well as the bug report.

PowerSet was added sometime back for completion sake but I will admit that I don’t think it’s used all that much. I have recently considered removing it because I couldn’t find a great solution that was generics compatible.

Your investigation is appreciated and I’ll see what I can do in the coming days.

from golang-set.

billinghamj avatar billinghamj commented on August 19, 2024 1

@deckarep Now that 1.18 is out, do you think you'd be interested in releasing the generics branch, perhaps with the 2 problematic methods removed?

from golang-set.

deckarep avatar deckarep commented on August 19, 2024 1

@billinghamj - sorry for the delay on this. I have finally got around to release a 2.0.0 tag using your changes to support the final release of Go 1.18.

Big thanks for sorting out the bug around any type not being comparable.

from golang-set.

billinghamj avatar billinghamj commented on August 19, 2024

Going through playing with some changes, for some of the tests, it seems there is no workaround to enable what they're trying to do

I've commented on the PR to flag that, as it seems odd to make this kind of code impossible to write

Edit: opened it as a new issue on the go repo - golang/go#51257

from golang-set.

billinghamj avatar billinghamj commented on August 19, 2024

For now, I've released here without the problematic methods, as a workaround: https://github.com/billinghamj/golang-set

from golang-set.

billinghamj avatar billinghamj commented on August 19, 2024

No problem πŸ™‚ I'm very happy to pitch in with anything if that'd be helpful too πŸ‘Œ

from golang-set.

billinghamj avatar billinghamj commented on August 19, 2024

@deckarep btw, now that Go 1.20 is out, I think those methods could be added back :)

I believe the issue was finally resolved by golang/go#56548, and that change went out in 1.20

from golang-set.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.