creativescala / doodle

Compositional vector graphics in Scala / Scala.JS
https://creativescala.org/doodle/
Apache License 2.0
327 stars 75 forks source link

Writer conveniences #149

Open noelwelsh opened 5 months ago

noelwelsh commented 5 months ago

There are two conveniences that will be useful on writers:

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.