Friday, July 27, 2012

Scala-IO Getting Started

For the next several posts you will need to have Scala-IO installed and probably should have a sbt project as well.

There are currently 2 Scala-IO 0.4 releases.

  • Scala-io 0.4-seq - A version of Scala 0.4 without the Akka dependency and therefore no ASync support
  • Scala-io 0.4 - The full version that contains an Akka  dependency
The Scala 2.10 versions will have no Akka dependency but can optionally use Akka.

So getting started:

Download the example project on the docs website (http://jesseeichar.github.com/scala-io-doc/latest):
  • Go to Getting Started and follow instructions for downloading and running the example project.  The following goes through the steps for the 0.4.1 instructions.


1
2
3
4
5
6
7
8
9
10
11
12
13
sbt console
 
scala> import scalax.io._
import scalax.io._
 
scala> import java.net.URL
import java.net.URL
 
scala> Resource.fromURL(new URL("http://www.scala-lang.com")).
     | lines().async.size.onComplete(println)
res3: akka.dispatch.Future[Int] = akka.dispatch.DefaultPromise@363adfb4
 
scala> Right(770)

The last line (Right(770)) is not a command to enter; it is the result of the asynchonous call.

1 comment:

  1. Awesome! Glad to see another post on the phenomenal Daily Scala again, too.

    ReplyDelete