FAQ
Hi,

I'm trying to factor my app to reduce some duplication and to do this,
I'm trying to define a function type that takes a bunch of well know
arguments and returns interface{}. However, the concrete functions I'm
passing all return an array of a specific type. The go compiler does
not like this.

What I'd like to do is:

http://play.golang.org/p/M1vEFHcgZM

But I can do the following to fix the issue:

http://play.golang.org/p/n37_NUu5Tr

However, I'd like not to have to dumb down the functions that are being called.

Is there a better way to achieve this?

Cheers,

Ben

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Search Discussions

  • Ian Lance Taylor at Nov 12, 2013 at 5:09 pm

    On Tue, Nov 12, 2013 at 8:10 AM, Ben Hood wrote:
    I'm trying to factor my app to reduce some duplication and to do this,
    I'm trying to define a function type that takes a bunch of well know
    arguments and returns interface{}. However, the concrete functions I'm
    passing all return an array of a specific type. The go compiler does
    not like this.

    What I'd like to do is:

    http://play.golang.org/p/M1vEFHcgZM

    But I can do the following to fix the issue:

    http://play.golang.org/p/n37_NUu5Tr

    However, I'd like not to have to dumb down the functions that are being called.
    What you want to do doesn't work because a []int doesn't look like an
    interface{}. There needs to be some code in there to convert from one
    to the other, and there isn't any place for such code to exist.

    I think the closest you can come in Go is to add that code yourself,
    as in http://play.golang.org/p/zlrHpvENre .

    Ian

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
    For more options, visit https://groups.google.com/groups/opt_out.
  • Ben Hood at Nov 12, 2013 at 5:36 pm
    Cool - that is not a bad suggestion, so thanks for you help.

    I take your point about that is going to be the best you can
    (currently) do in Go, but it will help my refactoring out quite a bit.

    Thanks for the point,

    Ben
    On Tue, Nov 12, 2013 at 5:09 PM, Ian Lance Taylor wrote:
    On Tue, Nov 12, 2013 at 8:10 AM, Ben Hood wrote:

    I'm trying to factor my app to reduce some duplication and to do this,
    I'm trying to define a function type that takes a bunch of well know
    arguments and returns interface{}. However, the concrete functions I'm
    passing all return an array of a specific type. The go compiler does
    not like this.

    What I'd like to do is:

    http://play.golang.org/p/M1vEFHcgZM

    But I can do the following to fix the issue:

    http://play.golang.org/p/n37_NUu5Tr

    However, I'd like not to have to dumb down the functions that are being called.
    What you want to do doesn't work because a []int doesn't look like an
    interface{}. There needs to be some code in there to convert from one
    to the other, and there isn't any place for such code to exist.

    I think the closest you can come in Go is to add that code yourself,
    as in http://play.golang.org/p/zlrHpvENre .

    Ian
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
    For more options, visit https://groups.google.com/groups/opt_out.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedNov 12, '13 at 4:10p
activeNov 12, '13 at 5:36p
posts3
users2
websitegolang.org

2 users in discussion

Ben Hood: 2 posts Ian Lance Taylor: 1 post

People

Translate

site design / logo © 2023 Grokbase