go - Loop over array of items that implement an interface -


suppose have array of items implement interface reader:

var items []foo 

how pass these items function takes readers?

func (items []reader) { ... } 

i can't use type []reader because error like:

cannot use type `[]foo` type `[]reader`... 

for example,

package main  import (     "bytes"     "io" )  var items []*bytes.buffer  func f(items []io.reader) {}  func main() {     readers := make([]io.reader, len(items))     i, item := range items {         readers[i] = item     }     f(readers) } 

Comments

Popular posts from this blog

cakephp - simple blog with croogo -

How to group boxplot outliers in gnuplot -

bash - Performing variable substitution in a string -