pureimage icon indicating copy to clipboard operation
pureimage copied to clipboard

Image.map is confusing

Open non opened this issue 11 years ago • 1 comments

So it seems like Image.map takes the size of the old image, but a new (Int, Int) => A function which it uses (ignoring the old raster's function).

This is a bit odd, right? I would imagine the map method as looking something more like this:

trait Image[A] { self =>
  ...
  def map[B](f: A => B): Image[B] = new Image[B] {
    def width = self.width
    def height = self.height
    def apply(x: Int, y: Int): B = f(self(x, y))
  }
}

I feel like the current map maybe belongs in a companion object? What is the advantage over just doing this:

object Image {
  def apply[A](w: Int, h: Int)(f: (Int, Int) => A): Image[A] = ...
}

What do you think?

non avatar Oct 21 '13 07:10 non

You're right. I should get rid of it.

stephenjudkins avatar Oct 21 '13 17:10 stephenjudkins