I've recently been trying to pull out useful pieces from some of my more
monolithic libraries. The most recent result is 'byte-streams' [1], a
library that figures how how to convert between different byte
representations (including character streams), and how to efficiently
transfer bytes between various byte sources and sinks. The net result is
that you can do something like:
(byte-streams/convert (File. "/tmp/foo") String {:encoding "utf-8"})
and get a string representation of the file's contents. Of course, this is
already possible using 'slurp', but you could also convert it to a
CharSequence, or lazy sequence of ByteBuffers, or pretty much anything else
you can imagine. This is accomplished by traversing a graph of available
conversions (don't worry, it's memoized), so simply defining a new
conversion from some custom type to (say) a ByteBuffer will transitively
allow you to convert it to any other type.
As an aside, this sort of conversion mechanism isn't limited to just byte
representations, but I'm not sure if there's another large collection of
mostly-isomorphic types out there that would benefit from this. If anyone
has ideas on where else this could be applied, I'd be interested to hear
them.
Zach
[1] https://github.com/ztellman/byte-streams
--
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Groups
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.