title: Why does the Go image package cut+paste looping over pixels?
body: <p>If you look at the image package here <a href="http://golang.org/src/pkg/image/image.go" rel="nofollow">http://golang.org/src/pkg/image/image.go</a> you can see that the implementation of Opaque() for every image does the same thing, differing only in the pixel-specific logic.</p>
  
  <p>Is there a reason for this?  Would any general solution be less efficient?  Is it just an oversight?  Is there some limitation (I cannot see one) to the type system that would make a polymorphic [was: generic] approach difficult?</p>
  
  <p>[edit] The kind of solution I was thinking of (which does not need generics in the Java sense) would be like:</p>
  
  <pre><code>
  type ColorPredicate func(c image.Color) bool;
  
  func AllPixels (p *image.Image, q ColorPredicate) bool {
    var r = p.Bounds()
    if r.Empty() {
      return true
    }
    for y := r.Min.Y; y &lt; r.Max.Y; y++ {
      for x := r.Min.X; x &lt; r.Max.X; x++ {
        if ! q(p.At(x,y)) {
          return false
        }
      }
    }
    return true
  }
  </code></pre>
  
  <p>but I am having trouble getting that to compile (still very new to Go - it will compile with an image, but not with an image pointer!).</p>
  
  <p>Is that too hard to optimise?  (you would need to have function inlining, but then wouldn't any type checking be pulled out of the loop?).  Also, I now realise I shouldn't have used the word "generic" earlier - I meant it only in a generic (ha) way.</p>