Thursday, July 26, 2012

Introducing Scala-IO


This is the start of a series of posts on Scala-IO.  Scala-IO is as the name implies a library for performing input and output operations with Scala.  There are 4 main facets to the library


  • Basic IO - Reading and writing to some underlying resource.  The current implementation is Java based and thus allows reading and writing to resources like java.io.Readers, Writers, Channels, Streams, etc...
  • File API - A library loosely designed after java 7 nio.file API with an additional simple unix like DSL for traversing and searching the filesystem.  It is a pluggable architecture which allows plugins for systems like WebDav or Zip filesystems to be addressed in a similar manner as the local filesystem.  The included implementation is for the local file system and is implemented on the java.io APIs
  • Asynchronous Access - Throughout the APIs are both synchronous and asynchronous options allowing both models of programming to be easily used.  
    • In the 2.10.x + versions the future implementations are pluggable but require no additional libraries if so that is the desire
    • In 2.9.x versions there are two different dependencies one with asynchronous APIs implemented on Akka and one without any asynchronous APIs
  • Processor API - An API for defining complex IO processes declaratively.
This series will look at normally a small and simple IO operation each day (or so) rather than only a few in-depth articles.  This is required because of my limited available time.

With the introduction done lets look at two small examples:

Read File with Core API (not File API):
Same thing but with File API:

12 comments:

  1. Oh, man, I love it when a long dormant RSS feed wakes up like this! I'm looking forward to this series.

    ReplyDelete
  2. Welcome back! Do you think you will talk about Functional IO too?
    See here for example: http://www.stackmob.com/2011/12/scalaz-post-part-2/

    ReplyDelete
    Replies
    1. A good idea. Will take a bit longer since I will have to research it. It would be a good idea though. While I am familiar with it I have not done a deep dive into it lately.

      Delete
  3. I am happy you are back. You lessons are very good!

    ReplyDelete
  4. Really happy to see this blog live again!

    ReplyDelete
  5. Nice to see a new post here! This was my favorite scala blog.

    ReplyDelete
  6. Being able to read the whole of a Resource is very handy, but names containing alimentary verbs like "slurp" are pretty unpleasant to me.

    ReplyDelete
  7. Honestly I don't have a strong opinion either way. Slurp was the name of the method when I started with the code base and I find it a very descriptive method so I didn't see a strong enough case for changing it. I realized that some people wouldn't love it but that is the case of most anything one does so as long as the intention is clear and the functionality is solid I am not sweating it too much.

    ReplyDelete
  8. I'm so happy you are back! This is the most helpful blog for the scala beginner!
    And thanks to you now I'm getting to higher-order kinds and typeclass pattern!

    ReplyDelete
  9. java.io, scala.io, scalax.io...? In .net I have just System.IO.
    Are you able to orientate me?

    ReplyDelete