Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add .Get() to Tuple family as alias for .Unpack() to match samber/mo #448

Open
jcbhmr opened this issue Apr 26, 2024 · 0 comments
Open

Add .Get() to Tuple family as alias for .Unpack() to match samber/mo #448

jcbhmr opened this issue Apr 26, 2024 · 0 comments

Comments

@jcbhmr
Copy link

jcbhmr commented Apr 26, 2024

basically this is the other end of samber/mo#40 -- implement .Get() -> (T, U, V, ...) for the Tuple family of types instead of having samber/mo's Result and Option implement .Unpack()

func (t *TupleN) Get() (T, U, V, ...) {
  return t.A, t.B, t.C, ...
}

why do I want this? so that I can use https://github.com/samber/mo Option Result and this package's Tuple interchangeably and just return an interface like this:

type myGet[T any, U any] interface {
  Get() (T, U)
}

func MyFunc() <-chan myGet[int, error] {
  c := make(chan myGet[int, error])
  go func(){
    defer close(c)
    time.Sleep(200 * time.Milliseconds)
    // c <- mo.Option
    // c <- lo.Tuple2
    // c <- mo.Result
    // c <- whatever
  }()
  return c
}
import "github.com/jcbhmr/thelib"

func main() {
  v, err := (<-thelib.MyFunc()).Get()
  if err != nil {
    log.Fatal(err)
  }
  log.Printf("The result is %d", v)
}

tldr: id like to see Unpack() or Get() be a common func among samber/lo and samber/mo so that I can return an interface abstracting over the library data structs that I use and just say "run .Unpack()" or "run .Get()"

@jcbhmr jcbhmr changed the title Add .Get() to Tuple family as common alias for .Unpack() to match samber/mo Add .Get() to Tuple family as alias for .Unpack() to match samber/mo Apr 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant