h1. Learning Scala with Play

Life’s too short to not learn Scala. The Play Scala module is the easiest way to learn it. Thanks to the interactive way Play will compile, execute and report errors on your Scala code, you can immediatly start to experiment Scala. 

h2. <a>Play with Scala</a>

**Play with Scala** is an application part of this module that allow you to interactively code and execute Scala code from your preferred text editor.

To run it, go to **$PLAY_HOME/modules/scala/samples-and-test/play-with-scala** directory, and type:

bc. $ play run

Then connect to "http://localhost:9000":http://localhost:9000 with your preferred web browser.

!images/play-with-scala!

Now open the **app/scrapbook.scala** file included in the application with any text editor:

bc. package play_with_scala {
 
    class Scrapbook {
        print("Howdy, open the app/scrapbook.scala file, and start to Play!") 
    }
 
}

The @Scrapbook@ class body will be automatically executed each time you refresh the Web page. Every @print@ or @println@ statement result will be displayed right into the Web page.

For example, discard the dummy default @print@ statement, and replace it with something more interesting:

bc. package play_with_scala {
 
    class Scrapbook {
        val numbers = 0 to 10
        
        print(numbers)
        
        val sum = numbers.reduceLeft( (a,b) => a + b )
        
        print(sum)
        
        val strings = numbers.map( a => "Number:" + a )
        
        print(strings)
        
        val odds = numbers.filter( _ % 2 == 0 )
        
        print(odds)
    }
 
}

And refresh your brower:

!images/play-with-scala2!

You are not limited to code in the @Scrapbook@ class, you can of course define any class or function your want:

bc. package play_with_scala {
 
    class Scrapbook {
        val users = List(
            User("guillame", "gbo@zenexity.com"),
            User("sadek", "sdr@zenexity.com")
        )
                    
        val allEmails = (users:List[User]) => {
            for( user <- users ) yield user.email
        }
                    
        print( allEmails(users) )
    }
    
    case class User(name: String, email: String)
 
}

That will display:

!images/play-with-scala3!

Of course, if we make an error, Play will display a clear error page:

!images/play-with-scala-error!

h2. <a>Resources</a>

The Play with Scala application links to several interesting resources that can help you to discover and learn Scala.

# "Scala for Java Refugees":http://www.codecommit.com/blog/scala/roundup-scala-for-java-refugees
# "Programming scala":http://programming-scala.labs.oreilly.com/
# "Ninety-Nine Scala Problems":http://aperiodic.net/phil/scala/s-99/
# "And of course the official scala website":http://www.scala-lang.org/