Though the above is not allowed, you can restructure your code to wrap your 
struct as array in another struct and have area() paas a index to the 
underlying struct. Something like this (landSpaceArr wraps landSpace 
struct) - 

type landSpace struct{
        side int
}

type landSpaceArr struct {
        lS []landSpace
}

func (s *landSpaceArr) area(i int) int {
        return s.lS[i].side * s.lS[i].side
}

type Shapes interface {
        area(int) int
}

func main() {

        v := make([]landSpace, 1)
        v[0].side =50
        a := &landSpaceArr{lS: v}

        processShapes(a, 0)
}

func processShapes(shapes Shapes, i int) {

        println(shapes.area(i))
}

~                                

On Thursday, April 19, 2018 at 10:29:12 AM UTC+5:30, Sakthi Natesan wrote:
>
> Usescases that I came across doesn't involve []interface{}. 
>
> My usecases will be similar to this sample code 
> <https://play.golang.org/p/LezKzpiMndl>
>
> type landSpace struct {
> //consider that landSpace implements all functions from both Shape and 
> property interfaces
> ...
> }
> type Shape interface {
> ...
> }
>
>
> type property interface {
>
> ...
> }
>
>
> var a []*landSpace
>
> func processShapes(shapes []Shape) {
> //....
> }
>
> func evaluateProperties(properties []Property) {
> //....
> }
>
>
>
> If I want to pass the variable 'a' to both the functions, then I have to 
> write two functions to clone and typeAssert to respective interfaces.
>
>
> On Wednesday, 18 April 2018 19:53:33 UTC+5:30, Jan Mercl wrote:
>>
>> On Wed, Apr 18, 2018 at 4:13 PM <nsak...@gmail.com> wrote:
>>
>> When possible, avoid using '[]interface{}' and use just 'interface{}' 
>> instead: https://play.golang.org/p/oPtPoGChkMZ.
>>
>>
>> -- 
>>
>> -j
>>
>
-- 
*::DISCLAIMER::

----------------------------------------------------------------------------------------------------------------------------------------------------


The contents of this e-mail and any attachments are confidential and 
intended for the named recipient(s) only.E-mail transmission is not 
guaranteed to be secure or error-free as information could be intercepted, 
corrupted,lost, destroyed, arrive late or incomplete, or may contain 
viruses in transmission. The e mail and its contents(with or without 
referred errors) shall therefore not attach any liability on the originator 
or redBus.com. Views or opinions, if any, presented in this email are 
solely those of the author and may not necessarily reflect the views or 
opinions of redBus.com. Any form of reproduction, dissemination, copying, 
disclosure, modification,distribution and / or publication of this message 
without the prior written consent of authorized representative of redbus. 
<http://redbus.in/>com is strictly prohibited. If you have received this 
email in error please delete it and notify the sender immediately.Before 
opening any email and/or attachments, please check them for viruses and 
other defects.*

-- 
*::DISCLAIMER::

----------------------------------------------------------------------------------------------------------------------------------------------------


The contents of this e-mail and any attachments are confidential and 
intended for the named recipient(s) only.E-mail transmission is not 
guaranteed to be secure or error-free as information could be intercepted, 
corrupted,lost, destroyed, arrive late or incomplete, or may contain 
viruses in transmission. The e mail and its contents(with or without 
referred errors) shall therefore not attach any liability on the originator 
or redBus.com. Views or opinions, if any, presented in this email are 
solely those of the author and may not necessarily reflect the views or 
opinions of redBus.com. Any form of reproduction, dissemination, copying, 
disclosure, modification,distribution and / or publication of this message 
without the prior written consent of authorized representative of redbus. 
<http://redbus.in/>com is strictly prohibited. If you have received this 
email in error please delete it and notify the sender immediately.Before 
opening any email and/or attachments, please check them for viruses and 
other defects.*

-- 
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 golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to