doodle icon indicating copy to clipboard operation
doodle copied to clipboard

Writer conveniences

Open noelwelsh opened this issue 11 months ago • 0 comments

There are two conveniences that will be useful on writers:

  • methods using a DefaultFrame (depends on #148) instead of requiring the user to pass a Frame
  • methods that return just the output type and discard the A value in the Picture (A is almost always Unit; discarding it is what draw does.)

These can both be implemented as syntax. (It's good to not have redundant methods on the type classes / algebras, though this is not consistently followed.)

(What's below is more speculative.)

There are a number of writers that don't require any input beyond the Picture and Frame (e.g. writing to an value, like Base64 or a BufferedImage). To ensure consistency for these kinds of writers we can define a subtype of Writer, let's say ValueWriter:

trait ValueWriter[..., Out] extends Writer [...] {
  def write(picture: ..., frame: ...): IO[(A, Out)]
}

Then we can define syntax on ValueWriter that all implementations will automatically have. Probably something like

picture.to[Out]

where the type variable Out is used to select the ValueWriter instance.

noelwelsh avatar Mar 13 '24 13:03 noelwelsh