Writing With Typeclasses

Details on how output is converted to bytes and how the design can be extended and used

Writing Arrays

Writing Arrays is a special situation because of how Java and Scala use arrays. For performance Scala uses the Java Array object and coerces them into Traversable objects when the Scala collections methods are needed. However the implicit resolution will not choose a TraversableConverter. Fortunately Scala IO provides several Converters for converting Arrays to bytes.

The point of this example is explain that if one is creating a custom converter he will have to consider creating both a OutputConverter[Traversable[_]] as well as a OutputConverter[Array[_]]

    import scalax.io._
    import Resource._

    val out = fromFileString("out")
    out.write(Array(1,2,3,4))(OutputConverter.IntAsByteArrayConverter)
    out.write(Array(1,2,3,4))