Scala on Androids




           Thor Åge Eldby

           @thoraageeldby
       1
Me
C/C
   ++
                a
             av
            lJ
         na
        so




                                 ...
Arktekk


• Started 2007
• Consultancy and training


                     3
Android
Fringe to mainstream




         4
Android 101




     5
Android 101




    Linux



      5
Android 101



OpenCore


               Linux



                 5
Android 101



OpenCore   SQLite


                    Linux



                      5
Android 101



                    OpenGL
OpenCore   SQLite
                      ES


                     Linux



     ...
Android 101



                    OpenGL
OpenCore   SQLite            WebKit
                      ES


                 ...
Android 101



                    OpenGL
OpenCore   SQLite            WebKit   Other
                      ES


         ...
Android 101


                    Dalvik


                    OpenGL
OpenCore   SQLite            WebKit   Other
        ...
Android 101
 Apache
Harmony


                    Dalvik


                    OpenGL
OpenCore   SQLite            WebKit ...
Android 101
 Apache
           HttpClient
Harmony


                        Dalvik


                        OpenGL
OpenCo...
Android 101
 Apache
           HttpClient   org.json
Harmony


                        Dalvik


                        Op...
Android 101
 Apache
           HttpClient   org.json   DOM/SAX
Harmony


                        Dalvik


                ...
Android 101
 Apache
           HttpClient   org.json   DOM/SAX   Android
Harmony


                        Dalvik


      ...
Android SDK
Android SDK
.java
files
Android SDK
.java
files
Android SDK
.java
files



javac
Android SDK
.java
files



javac
Android SDK
.java
files



javac



.class
 files
Android SDK
.java
files



javac



.class
 files
Android SDK
.java
files



javac



.class
 files
           dx
Android SDK
.java
files



javac



.class
 files
           dx
Android SDK
.java
files



javac



.class
 files             .dex
           dx
                   file
Android SDK
.java
files



javac



.class
 files             .dex
           dx
                   file
Android SDK
.java
files



javac



.class
 files             .dex   resou-
           dx
                   file    rces
Android SDK
.java
files



javac



.class
 files             .dex   resou-
           dx
                   file    rces
Android SDK
.java
files



javac
                         aapt

.class
 files             .dex      resou-
           dx
   ...
Android SDK
.java
files



javac
                         aapt

.class
 files             .dex      resou-
           dx
   ...
Android SDK
.java
files                     .apk
                          file

javac
                         aapt

.class...
Android SDK
.java
files                     .apk
                          file

javac
                         aapt

.class...
Android SDK
.java           adb
files                         .apk
                              file

javac
               ...
Android SDK
.java           adb
files                         .apk
                              file

javac
               ...
Android SDK
.java           adb
files                         .apk
                              file

javac
               ...
Android SDK
.java               adb
files                             .apk
                                  file

javac
   ...
Android Development
      Components




          7
Android Development
                  Components
   Activity

Text
Text
  Done   Cancel




                      7
Android Development
                  Components
   Activity         Service

Text
Text
  Done   Cancel




              ...
Android Development
                  Components
   Activity         Service    Broadcast-
                               ...
Android Development
                       Components
   Activity              Service    Broadcast-
                     ...
Android Development
                       Components
   Activity              Service    Broadcast-
                     ...
Android Development
                       Components
   Activity              Service    Broadcast-
                     ...
Littlebro
http://github.com/thoraage/littlebro-android
http://github.com/thoraage/jmx-rest-access




                    ...
Overview
  Android
  Littlebro




      9
Overview
   Android
   Littlebro


  Jetty / LIFT
JMX REST Access




       9
Overview
   Android
   Littlebro


  Jetty / LIFT
JMX REST Access


   Glassfish
     JMX
       9
Demo




 10
SBT


• http://code.google.com/p/simple-build-tool/


                     11
SBT

• Command line
• Maven source structure
• Configured in Scala

                    12
SBT Structure
|-- project
| |-- build
| | `-- Littlebro.scala
| |-- build.properties
| `-- plugins
|    `-- Plugins.scala
...
SBT Structure
|-- project
| |-- build
| | `-- Littlebro.scala
| |-- build.properties
| `-- plugins
|    `-- Plugins.scala
...
SBT Structure
|-- project
| |-- build
| | `-- Littlebro.scala
| |-- build.properties
| `-- plugins
|    `-- Plugins.scala
...
SBT Structure
|-- project
| |-- build
| | `-- Littlebro.scala
| |-- build.properties
| `-- plugins
|    `-- Plugins.scala
...
Scala 101
                   Traits
trait A { def a = "aaa" }
trait B { def b = "bbb" }




                            14
Scala 101
                   Traits
trait A { def a = "aaa" }
trait B { def b = "bbb" }




class C extends A with B {
  d...
Scala 101
                   Traits
trait A { def a = "aaa" }
trait B { def b = "bbb" }




class C extends A with B {
  d...
Scala 101
                   Traits
trait A { def a = "aaa" }
trait B { def b = "bbb" }




class C extends A with B {
  d...
Scala 101
                   Traits
trait A { def a = "aaa" }
trait B { def b = "bbb" }




class C extends A with B {
  d...
Project

class Littlebro(info: ProjectInfo)
  extends AndroidProject(info)
    with TypedResources
      with Eclipsify {
...
Project

class Littlebro(info: ProjectInfo)
  extends AndroidProject(info)
    with TypedResources
      with Eclipsify {
...
Project

class Littlebro(info: ProjectInfo)
  extends AndroidProject(info)
    with TypedResources
      with Eclipsify {
...
Project

class Littlebro(info: ProjectInfo)
  extends AndroidProject(info)
    with TypedResources
      with Eclipsify {
...
SBT & Android
• http://github.com/jberkel/android-plugin




                     16
SBT & Android
  • http://github.com/jberkel/android-plugin
scalac




                       16
SBT & Android
  • http://github.com/jberkel/android-plugin
scalac




                       16
SBT & Android
     • http://github.com/jberkel/android-plugin
  scalac


.class
 files



                          16
SBT & Android
     • http://github.com/jberkel/android-plugin
  scalac


.class
 files



                          16
SBT & Android
     • http://github.com/jberkel/android-plugin
  scalac


.class
 files

           ProGuard

              ...
SBT & Android
     • http://github.com/jberkel/android-plugin
  scalac


.class
 files

           ProGuard

              ...
SBT & Android
     • http://github.com/jberkel/android-plugin
  scalac


.class
 files                       less
         ...
SBT & Android
     • http://github.com/jberkel/android-plugin
  scalac


.class
 files                       less
         ...
SBT & Android
     • http://github.com/jberkel/android-plugin
  scalac


.class
 files                       less
         ...
SBT & Android
     • http://github.com/jberkel/android-plugin
  scalac


.class
 files                       less
         ...
SBT & Android
     • http://github.com/jberkel/android-plugin
  scalac

                                                  ...
Demo




 17
SBT & Idea

• http://github.com/mpeltonen/sbt-idea-plugin
• Hacked to work with sbt-android-plugin:
  http://github.com/th...
SBT & Eclipse


• http://github.com/musk/SbtEclipsify
• Not tested with Android


                     19
Scala on Androids
      Quick wins




          20
Resources
Resource xml’s and R.java




           21
Layout definition

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:a="http://schemas.android.com/apk/res/android...
Layout definition

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:a="http://schemas.android.com/apk/res/android...
R.java

public final class R {
    ...
    public static final class id {
        public static final int login=0x7f050001...
R.java

public final class R {
    ...
    public static final class id {
        public static final int login=0x7f050001...
R.java

public final class R {
    ...
    public static final class id {
        public static final int login=0x7f050001...
R.java
                                           Button?
public final class R {
    ...
    public static final class id ...
R.java

public final class R {
    ...
    public static final class id {
        public static final int login=0x7f050001...
R.java usage

• In java
  •   Button login = (Button) findViewById(R.id.login);




                              24
R.java usage

• In java
  •   Button login = (Button) findViewById(R.id.login);




                              24
R.java usage

• In java
  •   Button login = (Button) findViewById(R.id.login);




                              24
R.java usage

• In java
  •   Button login = (Button) findViewById(R.id.login);




• In Scala
  •   val login = findViewB...
R.java usage

• In java
  •   Button login = (Button) findViewById(R.id.login);




• In Scala
  •   val login = findViewB...
R.java usage

• In java
  •   Button login = (Button) findViewById(R.id.login);




• In Scala
  •   val login = findViewB...
TR.scala
   ...
object TR {
  val login = TypedResource[android.widget.Button](R.id.login)
}
...
trait TypedActivityHolder...
TR.scala
   ...
object TR {
  val login = TypedResource[android.widget.Button](R.id.login)
}
...
trait TypedActivityHolder...
TR.scala
   ...
object TR {
  val login = TypedResource[android.widget.Button](R.id.login)
}
...
trait TypedActivityHolder...
TR.scala
   ...
object TR {
  val login = TypedResource[android.widget.Button](R.id.login)
}
...
trait TypedActivityHolder...
TR.scala
   ...
object TR {
  val login = TypedResource[android.widget.Button](R.id.login)
}
...
trait TypedActivityHolder...
TR.scala
   ...
object TR {
  val login = TypedResource[android.widget.Button](R.id.login)
}
...
trait TypedActivityHolder...
TR.java usage


• With TR.scala
 •   val login = findView(TR.login)




                         26
Listeners



    27
Listeners
login.setOnClickListener(new View.OnClickListener() {
  public void onClick(View view) {
    ...
  }
}




     ...
Listeners
login.setOnClickListener(new View.OnClickListener() {
  public void onClick(View view) {
    ...
  }
}

login.se...
Scala 101
  Anonymous functions
class Printer[A](list: List[A]) {
  def printSome(p: A => Boolean): Unit =
    for (elem <...
Scala 101
  Anonymous functions
class Printer[A](list: List[A]) {
  def printSome(p: A => Boolean): Unit =
    for (elem <...
Scala 101
  Anonymous functions
class Printer[A](list: List[A]) {
  def printSome(p: A => Boolean): Unit =
    for (elem <...
Scala 101
  Anonymous functions
class Printer[A](list: List[A]) {
  def printSome(p: A => Boolean): Unit =
    for (elem <...
Scala 101
  Anonymous functions
class Printer[A](list: List[A]) {
  def printSome(p: A => Boolean): Unit =
    for (elem <...
Scala 101
  Anonymous functions
class Printer[A](list: List[A]) {
  def printSome(p: A => Boolean): Unit =
    for (elem <...
Scala 101
  Anonymous functions
class Printer[A](list: List[A]) {
  def printSome(p: A => Boolean): Unit =
    for (elem <...
Scala 101
  Anonymous functions
class Printer[A](list: List[A]) {
  def printSome(p: A => Boolean): Unit =
    for (elem <...
Scala 101
  Anonymous functions
class Printer[A](list: List[A]) {
  def printSome(p: A => Boolean): Unit =
    for (elem <...
Scala 101
  Anonymous functions
class Printer[A](list: List[A]) {
  def printSome(p: A => Boolean): Unit =
    for (elem <...
Scala 101
  Anonymous functions
class Printer[A](list: List[A]) {
  def printSome(p: A => Boolean): Unit =
    for (elem <...
Scala 101
  Anonymous functions
class Printer[A](list: List[A]) {
  def printSome(p: A => Boolean): Unit =
    for (elem <...
Listeners
def onClick(f: View => Unit) {
  setOnClickListener(new View.OnClickListener {
     override def onClick(v: View...
Listeners
def onClick(f: View => Unit) {
  setOnClickListener(new View.OnClickListener {
     override def onClick(v: View...
Listeners
def onClick(f: View => Unit) {
  setOnClickListener(new View.OnClickListener {
     override def onClick(v: View...
Listeners
def onClick(f: View => Unit) {
  setOnClickListener(new View.OnClickListener {
     override def onClick(v: View...
Scala 101
      Implicit conversion
class AmendedString(s: String) {
  def rot13 = new String(for (c <- s) yield rotC(c))
...
Scala 101
      Implicit conversion
class AmendedString(s: String) {
  def rot13 = new String(for (c <- s) yield rotC(c))
...
Scala 101
      Implicit conversion
class AmendedString(s: String) {
  def rot13 = new String(for (c <- s) yield rotC(c))
...
Scala 101
      Implicit conversion
class AmendedString(s: String) {
  def rot13 = new String(for (c <- s) yield rotC(c))
...
Scala 101
      Implicit conversion
class AmendedString(s: String) {
  def rot13 = new String(for (c <- s) yield rotC(c))
...
Scala 101
      Implicit conversion
class AmendedString(s: String) {
  def rot13 = new String(for (c <- s) yield rotC(c))
...
Scala 101
      Implicit conversion
class AmendedString(s: String) {
  def rot13 = new String(for (c <- s) yield rotC(c))
...
Scala 101
      Implicit conversion
class AmendedString(s: String) {
  def rot13 = new String(for (c <- s) yield rotC(c))
...
Scala 101
      Implicit conversion
class AmendedString(s: String) {
  def rot13 = new String(for (c <- s) yield rotC(c))
...
Scala 101
      Implicit conversion
class AmendedString(s: String) {
  def rot13 = new String(for (c <- s) yield rotC(c))
...
Scala 101
      Implicit conversion
class AmendedString(s: String) {
  def rot13 = new String(for (c <- s) yield rotC(c))
...
Listeners
class AmendedView(view: View) {
  def onClick(f: View => Unit) {
    view.setOnClickListener(new View.OnClickLis...
Listeners
class AmendedView(view: View) {
  def onClick(f: View => Unit) {
    view.setOnClickListener(new View.OnClickLis...
Listeners
class AmendedView(view: View) {
  def onClick(f: View => Unit) {
    view.setOnClickListener(new View.OnClickLis...
Listeners
class AmendedView(view: View) {
  def onClick(f: View => Unit) {
    view.setOnClickListener(new View.OnClickLis...
Listeners
class AmendedView(view: View) {
  def onClick(f: View => Unit) {
    view.setOnClickListener(new View.OnClickLis...
Listeners
class AmendedView(view: View) {
  def onClick(f: View => Unit) {
    view.setOnClickListener(new View.OnClickLis...
Listeners
class AmendedView(view: View) {
  def onClick(f: View => Unit) {
    view.setOnClickListener(new View.OnClickLis...
Listeners
class AmendedView(view: View) {
  def onClick(f: View => Unit) {
    view.setOnClickListener(new View.OnClickLis...
Listeners
class AmendedView(view: View) {
  def onClick(f: View => Unit) {
    view.setOnClickListener(new View.OnClickLis...
Listeners
class AmendedView(view: View) {
  def onClick(f: View => Unit) {
    view.setOnClickListener(new View.OnClickLis...
Listeners
class AmendedView(view: View) {
  def onClick(f: View => Unit) {
    view.setOnClickListener(new View.OnClickLis...
Concurrency



     33
Responsiveness
• Separate work and GUI
  GUI thread




                   34
Responsiveness
• Separate work and GUI
  GUI thread




                   34
Responsiveness
 GUI thread                  worker


              Start worker




                 35
Responsiveness

new AsyncTask[Object, Void, Object]() {
  override def doInBackground(objects: Object*): Object = {
    .....
Responsiveness

new AsyncTask[Object, Void, Object]() {
  override def doInBackground(objects: Object*): Object = {
    .....
Responsiveness

new AsyncTask[Object, Void, Object]() {
  override def doInBackground(objects: Object*): Object = {
    .....
Responsiveness

new AsyncTask[Object, Void, Object]() {
  override def doInBackground(objects: Object*): Object = {
    .....
Responsiveness

new AsyncTask[Object, Void, Object]() {
  override def doInBackground(objects: Object*): Object = {
    .....
Responsiveness

new AsyncTask[Object, Void, Object]() {
  override def doInBackground(objects: Object*): Object = {
    .....
Responsiveness
 GUI thread                    worker


                Start worker




              Update GUI




     ...
Responsiveness

runOnUiThread(new Runnable() {
   def run: Unit = {
     ... update GUI
   }
})




                      ...
Responsiveness

runOnUiThread(new Runnable() {
   def run: Unit = {
     ... update GUI
   }
})




                      ...
Responsiveness

runOnUiThread(new Runnable() {
   def run: Unit = {
     ... update GUI
   }
})




                      ...
Responsiveness

runOnUiThread(new Runnable() {
   def run: Unit = {
     ... update GUI
   }
})




                      ...
Responsiveness

runOnUiThread(new Runnable() {
   def run: Unit = {
     ... update GUI
   }
})




                      ...
Responsiveness
new AsyncTask[Object, Void, Object]() {
  override def doInBackground(objects: Object*): Object = {
    ......
Responsiveness
new AsyncTask[Object, Void, Object]() {
  override def doInBackground(objects: Object*): Object = {
    ......
Responsiveness
new AsyncTask[Object, Void, Object]() {
  override def doInBackground(objects: Object*): Object = {
    ......
Responsiveness
new AsyncTask[Object, Void, Object]() {
  override def doInBackground(objects: Object*): Object = {
    ......
Responsiveness
new AsyncTask[Object, Void, Object]() {
  override def doInBackground(objects: Object*): Object = {
    ......
Responsiveness
new AsyncTask[Object, Void, Object]() {
  override def doInBackground(objects: Object*): Object = {
    ......
Responsiveness
new AsyncTask[Object, Void, Object]() {
  override def doInBackground(objects: Object*): Object = {
    ......
Responsiveness
new AsyncTask[Object, Void, Object]() {
  override def doInBackground(objects: Object*): Object = {
    ......
Responsiveness
new AsyncTask[Object, Void, Object]() {
  override def doInBackground(objects: Object*): Object = {
    ......
Responsiveness
new AsyncTask[Object, Void, Object]() {
  override def doInBackground(objects: Object*): Object = {
    ......
Responsiveness
asyncTask {

    ... do hard work
    onUiThread {

        ... update GUI

    }

}




                  ...
Further



   42
Actors
Organizing with asynchronous message passing




                     43
Scala 101
                  Actors
object MyActor extends Actor {
  def act {
    loop {
      react {
        case msg:St...
Scala 101
                  Actors
object MyActor extends Actor {
  def act {
    loop {
      react {
        case msg:St...
Scala 101
                  Actors
object MyActor extends Actor {
  def act {
    loop {
      react {
        case msg:St...
Scala 101
                  Actors
object MyActor extends Actor {
  def act {
    loop {
      react {
        case msg:St...
Scala 101
                  Actors
object MyActor extends Actor {
  def act {
    loop {
      react {
        case msg:St...
Scala 101
                  Actors
object MyActor extends Actor {
  def act {
    loop {
      react {
        case msg:St...
Scala 101
                  Actors
object MyActor extends Actor {
  def act {
    loop {
      react {
        case msg:St...
Scala 101
                  Actors
object MyActor extends Actor {
  def act {
    loop {
      react {
        case msg:St...
Scala 101
                  Actors
object MyActor extends Actor {
  def act {
    loop {
      react {
        case msg:St...
Scala 101
                  Actors
object MyActor extends Actor {
  def act {
    loop {
      react {
        case msg:St...
Scala 101
                  Actors
object MyActor extends Actor {
  def act {
    loop {
      react {
        case msg:St...
Scala 101
                  Actors
object MyActor extends Actor {
  def act {
    loop {
      react {
        case msg:St...
Scala 101
                  Actors
object MyActor extends Actor {
  def act {
    loop {
      react {
        case msg:St...
Scala 101
                  Actors
object MyActor extends Actor {
  def act {
    loop {
      react {
        case msg:St...
Scala 101
                  Actors
object MyActor extends Actor {
  def act {
    loop {
      react {
        case msg:St...
Scala 101
                  Actors
object MyActor extends Actor {
  def act {
    loop {
      react {
        case msg:St...
Scala 101
                  Actors
object MyActor extends Actor {
  def act {
    loop {
      react {
        case msg:St...
Scala 101
                  Actors
object MyActor extends Actor {
  def act {
    loop {
      react {
        case msg:St...
Scala 101
                  Actors
object MyActor extends Actor {
  def act {
    loop {
      react {
        case msg:St...
Actors
GUI                     Connection                  Model Factory                    ViewStack


       href, (xml,...
Actors
GUI                     Connection                  Model Factory                    ViewStack


       href, (xml,...
Actors
GUI                     Connection                  Model Factory                    ViewStack


       href, (xml,...
Actors
GUI                     Connection                  Model Factory                    ViewStack


       href, (xml,...
Actors
GUI                     Connection                  Model Factory                    ViewStack


       href, (xml,...
Actors
GUI                     Connection                  Model Factory                    ViewStack


       href, (xml,...
Actors
GUI                     Connection                  Model Factory                    ViewStack


       href, (xml,...
Actors
GUI                     Connection                  Model Factory                    ViewStack


       href, (xml,...
Actors
GUI                     Connection                  Model Factory                    ViewStack


       href, (xml,...
Actors
GUI                     Connection                  Model Factory                    ViewStack


       href, (xml,...
Actors
GUI                     Connection                  Model Factory                    ViewStack


       href, (xml,...
Actors
GUI                     Connection                  Model Factory                    ViewStack


       href, (xml,...
Actors
GUI                     Connection                  Model Factory                    ViewStack


       href, (xml,...
Actors
GUI                     Connection                  Model Factory                    ViewStack


       href, (xml,...
Actors
GUI                     Connection                  Model Factory                    ViewStack


       href, (xml,...
Actors

case class Routing(success: Option[Actor],
                   failure: Option[Actor])
case class HttpRequestMsg(hr...
Actors

case class Routing(success: Option[Actor],
                   failure: Option[Actor])
case class HttpRequestMsg(hr...
Actors

case class Routing(success: Option[Actor],
                   failure: Option[Actor])
case class HttpRequestMsg(hr...
Actors

case class Routing(success: Option[Actor],
                   failure: Option[Actor])
case class HttpRequestMsg(hr...
Actors

case class Routing(success: Option[Actor],
                   failure: Option[Actor])
case class HttpRequestMsg(hr...
Actors

case class Routing(success: Option[Actor],
                   failure: Option[Actor])
case class HttpRequestMsg(hr...
Actors

case class Routing(success: Option[Actor],
                   failure: Option[Actor])
case class HttpRequestMsg(hr...
Actors

case class Routing(success: Option[Actor],
                   failure: Option[Actor])
case class HttpRequestMsg(hr...
Actors

case class Routing(success: Option[Actor],
                   failure: Option[Actor])
case class HttpRequestMsg(hr...
Actors

case class Routing(success: Option[Actor],
                   failure: Option[Actor])
case class HttpRequestMsg(hr...
Actors

case class Routing(success: Option[Actor],
                   failure: Option[Actor])
case class HttpRequestMsg(hr...
Actors

case class Routing(success: Option[Actor],
                   failure: Option[Actor])
case class HttpRequestMsg(hr...
Actors

case class Routing(success: Option[Actor],
                   failure: Option[Actor])
case class HttpRequestMsg(hr...
Actors

case class Routing(success: Option[Actor],
                   failure: Option[Actor])
case class HttpRequestMsg(hr...
Actors

case class Routing(success: Option[Actor],
                   failure: Option[Actor])
case class HttpRequestMsg(hr...
Actors

case class Routing(success: Option[Actor],
                   failure: Option[Actor])
case class HttpRequestMsg(hr...
Actors

case class Routing(success: Option[Actor],
                   failure: Option[Actor])
case class HttpRequestMsg(hr...
Actors

case class Routing(success: Option[Actor],
                   failure: Option[Actor])
case class HttpRequestMsg(hr...
Actors

case class Routing(success: Option[Actor],
                   failure: Option[Actor])
case class HttpRequestMsg(hr...
Actors

case class Routing(success: Option[Actor],
                   failure: Option[Actor])
case class HttpRequestMsg(hr...
Actors

case class Routing(success: Option[Actor],
                   failure: Option[Actor])
case class HttpRequestMsg(hr...
Actors

case class Routing(success: Option[Actor],
                   failure: Option[Actor])
case class HttpRequestMsg(hr...
Actors

case class Routing(success: Option[Actor],
                   failure: Option[Actor])
case class HttpRequestMsg(hr...
Actors

case class Routing(success: Option[Actor],
                   failure: Option[Actor])
case class HttpRequestMsg(hr...
Actor
      object Connection extends Actor {
    def retrieve(href: String): Either[Node, Failure] =
       Right(new Fai...
Actor
      object Connection extends Actor {
    def retrieve(href: String): Either[Node, Failure] =
       Right(new Fai...
Actor
      object Connection extends Actor {
    def retrieve(href: String): Either[Node, Failure] =
       Right(new Fai...
Actor
      object Connection extends Actor {
    def retrieve(href: String): Either[Node, Failure] =
       Right(new Fai...
Actor
      object Connection extends Actor {
    def retrieve(href: String): Either[Node, Failure] =
       Right(new Fai...
Actor
      object Connection extends Actor {
    def retrieve(href: String): Either[Node, Failure] =
       Right(new Fai...
Actor
      object Connection extends Actor {
    def retrieve(href: String): Either[Node, Failure] =
       Right(new Fai...
Actor
      object Connection extends Actor {
    def retrieve(href: String): Either[Node, Failure] =
       Right(new Fai...
Actor
      object Connection extends Actor {
    def retrieve(href: String): Either[Node, Failure] =
       Right(new Fai...
Actor
      object Connection extends Actor {
    def retrieve(href: String): Either[Node, Failure] =
       Right(new Fai...
Actor
      object Connection extends Actor {
    def retrieve(href: String): Either[Node, Failure] =
       Right(new Fai...
Actor
      object Connection extends Actor {
    def retrieve(href: String): Either[Node, Failure] =
       Right(new Fai...
Actor
      object Connection extends Actor {
    def retrieve(href: String): Either[Node, Failure] =
       Right(new Fai...
Androids on Scala




                 Fini

            @thoraageeldby
       48
Upcoming SlideShare
Loading in...5
×

Scala on androids

2,265

Published on

Talk on Scala development on Android

Published in: Technology
1 Comment
7 Likes
Statistics
Notes
  • Presentation at JavaZone: http://streaming.java.no/tcs/?id=97A469FD-3DDE-4692-85E9-651CFFCCC918 (in norwegian)
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
No Downloads
Views
Total Views
2,265
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
93
Comments
1
Likes
7
Embeds 0
No embeds

No notes for slide



  • Fringe: J2ME and Windows Mobile
    No working market
    Mainstream: Android and iPhone
    Android bigger than iPhone
    GOOGLE
    Customisable: Open source, Linux
    Exploding platform
    Mobile, TV, Pad
    Specialised devices will come
  • Telephones running UNIX
    (OpenCore media library)
    Dalvik ~= JVM
    Develop in java
    Harmony - Subset base class library
    GUI, bluetooth, WiFi, telephony, location, other hardware
  • Telephones running UNIX
    (OpenCore media library)
    Dalvik ~= JVM
    Develop in java
    Harmony - Subset base class library
    GUI, bluetooth, WiFi, telephony, location, other hardware
  • Telephones running UNIX
    (OpenCore media library)
    Dalvik ~= JVM
    Develop in java
    Harmony - Subset base class library
    GUI, bluetooth, WiFi, telephony, location, other hardware
  • Telephones running UNIX
    (OpenCore media library)
    Dalvik ~= JVM
    Develop in java
    Harmony - Subset base class library
    GUI, bluetooth, WiFi, telephony, location, other hardware
  • Telephones running UNIX
    (OpenCore media library)
    Dalvik ~= JVM
    Develop in java
    Harmony - Subset base class library
    GUI, bluetooth, WiFi, telephony, location, other hardware
  • Telephones running UNIX
    (OpenCore media library)
    Dalvik ~= JVM
    Develop in java
    Harmony - Subset base class library
    GUI, bluetooth, WiFi, telephony, location, other hardware
  • Telephones running UNIX
    (OpenCore media library)
    Dalvik ~= JVM
    Develop in java
    Harmony - Subset base class library
    GUI, bluetooth, WiFi, telephony, location, other hardware
  • Telephones running UNIX
    (OpenCore media library)
    Dalvik ~= JVM
    Develop in java
    Harmony - Subset base class library
    GUI, bluetooth, WiFi, telephony, location, other hardware
  • Telephones running UNIX
    (OpenCore media library)
    Dalvik ~= JVM
    Develop in java
    Harmony - Subset base class library
    GUI, bluetooth, WiFi, telephony, location, other hardware
  • Telephones running UNIX
    (OpenCore media library)
    Dalvik ~= JVM
    Develop in java
    Harmony - Subset base class library
    GUI, bluetooth, WiFi, telephony, location, other hardware
  • Telephones running UNIX
    (OpenCore media library)
    Dalvik ~= JVM
    Develop in java
    Harmony - Subset base class library
    GUI, bluetooth, WiFi, telephony, location, other hardware
  • Telephones running UNIX
    (OpenCore media library)
    Dalvik ~= JVM
    Develop in java
    Harmony - Subset base class library
    GUI, bluetooth, WiFi, telephony, location, other hardware






























  • Build system
    Used in Scala-community


  • build.properties
    Version, project name, scala version
    build - project definition
    plugins - definition of plugins used
  • build.properties
    Version, project name, scala version
    build - project definition
    plugins - definition of plugins used
  • build.properties
    Version, project name, scala version
    build - project definition
    plugins - definition of plugins used




  • ProjectInfo - external properties, paths
    Eclipsify
    Eclipse for nice colours
  • ProjectInfo - external properties, paths
    Eclipsify
    Eclipse for nice colours
  • ProjectInfo - external properties, paths
    Eclipsify
    Eclipse for nice colours
  • ProGuard
    Reflection
    Hello world example -&gt; 5kb
    Littlebro + 2.7.7 -&gt; 100kb
    Littlebro + 2.8.0 -&gt; 200kb
  • ProGuard
    Reflection
    Hello world example -&gt; 5kb
    Littlebro + 2.7.7 -&gt; 100kb
    Littlebro + 2.8.0 -&gt; 200kb
  • ProGuard
    Reflection
    Hello world example -&gt; 5kb
    Littlebro + 2.7.7 -&gt; 100kb
    Littlebro + 2.8.0 -&gt; 200kb
  • ProGuard
    Reflection
    Hello world example -&gt; 5kb
    Littlebro + 2.7.7 -&gt; 100kb
    Littlebro + 2.8.0 -&gt; 200kb
  • ProGuard
    Reflection
    Hello world example -&gt; 5kb
    Littlebro + 2.7.7 -&gt; 100kb
    Littlebro + 2.8.0 -&gt; 200kb
  • ProGuard
    Reflection
    Hello world example -&gt; 5kb
    Littlebro + 2.7.7 -&gt; 100kb
    Littlebro + 2.8.0 -&gt; 200kb
  • ProGuard
    Reflection
    Hello world example -&gt; 5kb
    Littlebro + 2.7.7 -&gt; 100kb
    Littlebro + 2.8.0 -&gt; 200kb
  • ProGuard
    Reflection
    Hello world example -&gt; 5kb
    Littlebro + 2.7.7 -&gt; 100kb
    Littlebro + 2.8.0 -&gt; 200kb
  • ProGuard
    Reflection
    Hello world example -&gt; 5kb
    Littlebro + 2.7.7 -&gt; 100kb
    Littlebro + 2.8.0 -&gt; 200kb
  • ProGuard
    Reflection
    Hello world example -&gt; 5kb
    Littlebro + 2.7.7 -&gt; 100kb
    Littlebro + 2.8.0 -&gt; 200kb
  • ProGuard
    Reflection
    Hello world example -&gt; 5kb
    Littlebro + 2.7.7 -&gt; 100kb
    Littlebro + 2.8.0 -&gt; 200kb




  • R[esources].java
    Aids resource lookup

  • Type lost
  • Type lost
  • Type lost
  • Type lost
  • Needs cast
    Scala accepts casting very reluctantly
    asInstanceOf is a method (final)
    Accept a generic argument
  • Needs cast
    Scala accepts casting very reluctantly
    asInstanceOf is a method (final)
    Accept a generic argument
  • Needs cast
    Scala accepts casting very reluctantly
    asInstanceOf is a method (final)
    Accept a generic argument
  • Needs cast
    Scala accepts casting very reluctantly
    asInstanceOf is a method (final)
    Accept a generic argument
  • Needs cast
    Scala accepts casting very reluctantly
    asInstanceOf is a method (final)
    Accept a generic argument
  • Generated by SBT android plugin
    with TypedActivity
  • Generated by SBT android plugin
    with TypedActivity
  • Generated by SBT android plugin
    with TypedActivity
  • Generated by SBT android plugin
    with TypedActivity
  • Generated by SBT android plugin
    with TypedActivity


  • In java
    In scala
    Can we do better?











  • Button extends View
    Can not add functions
  • Button extends View
    Can not add functions
  • Button extends View
    Can not add functions










  • Add methods to class
    Implicit conversion
    Must be imported
    onClick
    View =&gt; Unit
  • Add methods to class
    Implicit conversion
    Must be imported
    onClick
    View =&gt; Unit
  • Add methods to class
    Implicit conversion
    Must be imported
    onClick
    View =&gt; Unit
  • Add methods to class
    Implicit conversion
    Must be imported
    onClick
    View =&gt; Unit
  • Add methods to class
    Implicit conversion
    Must be imported
    onClick
    View =&gt; Unit
  • Add methods to class
    Implicit conversion
    Must be imported
    onClick
    View =&gt; Unit
  • Add methods to class
    Implicit conversion
    Must be imported
    onClick
    View =&gt; Unit
  • Add methods to class
    Implicit conversion
    Must be imported
    onClick
    View =&gt; Unit
  • Add methods to class
    Implicit conversion
    Must be imported
    onClick
    View =&gt; Unit
  • Add methods to class
    Implicit conversion
    Must be imported
    onClick
    View =&gt; Unit

  • I.e calculation or network
    5 seconds &amp; a touch
    Developer guide
    Design for responsiveness

  • Android provided asynchronous task
    Drawback: Single thread; not thread pool
  • Android provided asynchronous task
    Drawback: Single thread; not thread pool
  • Android provided asynchronous task
    Drawback: Single thread; not thread pool
  • Android provided asynchronous task
    Drawback: Single thread; not thread pool
  • Android provided asynchronous task
    Drawback: Single thread; not thread pool
  • We need to update GUI
  • Activity.runOnUiThread(Runnable)
  • Activity.runOnUiThread(Runnable)
  • Activity.runOnUiThread(Runnable)
  • Activity.runOnUiThread(Runnable)
  • Combined version
    Drop noise code
    Same trick as with listeners
  • Combined version
    Drop noise code
    Same trick as with listeners
  • Combined version
    Drop noise code
    Same trick as with listeners
  • Combined version
    Drop noise code
    Same trick as with listeners
  • Combined version
    Drop noise code
    Same trick as with listeners
  • Combined version
    Drop noise code
    Same trick as with listeners
  • Combined version
    Drop noise code
    Same trick as with listeners
  • Combined version
    Drop noise code
    Same trick as with listeners
  • Drop more noise code
    Drop AsyncTask object
    Drop execute






















  • Pass data needed with success and failure path
  • Pass data needed with success and failure path
  • Pass data needed with success and failure path
  • Pass data needed with success and failure path
  • Pass data needed with success and failure path
  • Pass data needed with success and failure path
  • Pass data needed with success and failure path
  • Pass data needed with success and failure path
  • Pass data needed with success and failure path
  • Pass data needed with success and failure path
  • Pass data needed with success and failure path
  • Pass data needed with success and failure path
  • Pass data needed with success and failure path
  • Pass data needed with success and failure path




































  • Scala on androids

    1. 1. Scala on Androids Thor Åge Eldby @thoraageeldby 1
    2. 2. Me C/C ++ a av lJ na so J2M r Pe E Java An dro id Scala 2
    3. 3. Arktekk • Started 2007 • Consultancy and training 3
    4. 4. Android Fringe to mainstream 4
    5. 5. Android 101 5
    6. 6. Android 101 Linux 5
    7. 7. Android 101 OpenCore Linux 5
    8. 8. Android 101 OpenCore SQLite Linux 5
    9. 9. Android 101 OpenGL OpenCore SQLite ES Linux 5
    10. 10. Android 101 OpenGL OpenCore SQLite WebKit ES Linux 5
    11. 11. Android 101 OpenGL OpenCore SQLite WebKit Other ES Linux 5
    12. 12. Android 101 Dalvik OpenGL OpenCore SQLite WebKit Other ES Linux 5
    13. 13. Android 101 Apache Harmony Dalvik OpenGL OpenCore SQLite WebKit Other ES Linux 5
    14. 14. Android 101 Apache HttpClient Harmony Dalvik OpenGL OpenCore SQLite WebKit Other ES Linux 5
    15. 15. Android 101 Apache HttpClient org.json Harmony Dalvik OpenGL OpenCore SQLite WebKit Other ES Linux 5
    16. 16. Android 101 Apache HttpClient org.json DOM/SAX Harmony Dalvik OpenGL OpenCore SQLite WebKit Other ES Linux 5
    17. 17. Android 101 Apache HttpClient org.json DOM/SAX Android Harmony Dalvik OpenGL OpenCore SQLite WebKit Other ES Linux 5
    18. 18. Android SDK
    19. 19. Android SDK .java files
    20. 20. Android SDK .java files
    21. 21. Android SDK .java files javac
    22. 22. Android SDK .java files javac
    23. 23. Android SDK .java files javac .class files
    24. 24. Android SDK .java files javac .class files
    25. 25. Android SDK .java files javac .class files dx
    26. 26. Android SDK .java files javac .class files dx
    27. 27. Android SDK .java files javac .class files .dex dx file
    28. 28. Android SDK .java files javac .class files .dex dx file
    29. 29. Android SDK .java files javac .class files .dex resou- dx file rces
    30. 30. Android SDK .java files javac .class files .dex resou- dx file rces
    31. 31. Android SDK .java files javac aapt .class files .dex resou- dx file rces
    32. 32. Android SDK .java files javac aapt .class files .dex resou- dx file rces
    33. 33. Android SDK .java files .apk file javac aapt .class files .dex resou- dx file rces
    34. 34. Android SDK .java files .apk file javac aapt .class files .dex resou- dx file rces
    35. 35. Android SDK .java adb files .apk file javac aapt .class files .dex resou- dx file rces
    36. 36. Android SDK .java adb files .apk file javac aapt .class files .dex resou- dx file rces
    37. 37. Android SDK .java adb files .apk file javac aapt .class files .dex resou- dx file rces
    38. 38. Android SDK .java adb files .apk file javac aapt .class files .dex resou- dx file rces 6
    39. 39. Android Development Components 7
    40. 40. Android Development Components Activity Text Text Done Cancel 7
    41. 41. Android Development Components Activity Service Text Text Done Cancel 7
    42. 42. Android Development Components Activity Service Broadcast- Receiver Text Text Done Cancel 7
    43. 43. Android Development Components Activity Service Broadcast- Receiver Text Text Done Cancel Intent 7
    44. 44. Android Development Components Activity Service Broadcast- Receiver Text Text Done Cancel Intent 7
    45. 45. Android Development Components Activity Service Broadcast- Receiver Text Text Done Cancel Intent 7
    46. 46. Littlebro http://github.com/thoraage/littlebro-android http://github.com/thoraage/jmx-rest-access 8
    47. 47. Overview Android Littlebro 9
    48. 48. Overview Android Littlebro Jetty / LIFT JMX REST Access 9
    49. 49. Overview Android Littlebro Jetty / LIFT JMX REST Access Glassfish JMX 9
    50. 50. Demo 10
    51. 51. SBT • http://code.google.com/p/simple-build-tool/ 11
    52. 52. SBT • Command line • Maven source structure • Configured in Scala 12
    53. 53. SBT Structure |-- project | |-- build | | `-- Littlebro.scala | |-- build.properties | `-- plugins | `-- Plugins.scala 13
    54. 54. SBT Structure |-- project | |-- build | | `-- Littlebro.scala | |-- build.properties | `-- plugins | `-- Plugins.scala 13
    55. 55. SBT Structure |-- project | |-- build | | `-- Littlebro.scala | |-- build.properties | `-- plugins | `-- Plugins.scala 13
    56. 56. SBT Structure |-- project | |-- build | | `-- Littlebro.scala | |-- build.properties | `-- plugins | `-- Plugins.scala 13
    57. 57. Scala 101 Traits trait A { def a = "aaa" } trait B { def b = "bbb" } 14
    58. 58. Scala 101 Traits trait A { def a = "aaa" } trait B { def b = "bbb" } class C extends A with B { def c = "ccc" } 14
    59. 59. Scala 101 Traits trait A { def a = "aaa" } trait B { def b = "bbb" } class C extends A with B { def c = "ccc" } val c = new C println(c.a + c.b + c.c) 14
    60. 60. Scala 101 Traits trait A { def a = "aaa" } trait B { def b = "bbb" } class C extends A with B { def c = "ccc" } val c = new C println(c.a + c.b + c.c) 14
    61. 61. Scala 101 Traits trait A { def a = "aaa" } trait B { def b = "bbb" } class C extends A with B { def c = "ccc" } val c = new C println(c.a + c.b + c.c) aaabbbccc 14
    62. 62. Project class Littlebro(info: ProjectInfo) extends AndroidProject(info) with TypedResources with Eclipsify { override def androidPlatformName = "android-1.5" } 15
    63. 63. Project class Littlebro(info: ProjectInfo) extends AndroidProject(info) with TypedResources with Eclipsify { override def androidPlatformName = "android-1.5" } 15
    64. 64. Project class Littlebro(info: ProjectInfo) extends AndroidProject(info) with TypedResources with Eclipsify { override def androidPlatformName = "android-1.5" } 15
    65. 65. Project class Littlebro(info: ProjectInfo) extends AndroidProject(info) with TypedResources with Eclipsify { override def androidPlatformName = "android-1.5" } 15
    66. 66. SBT & Android • http://github.com/jberkel/android-plugin 16
    67. 67. SBT & Android • http://github.com/jberkel/android-plugin scalac 16
    68. 68. SBT & Android • http://github.com/jberkel/android-plugin scalac 16
    69. 69. SBT & Android • http://github.com/jberkel/android-plugin scalac .class files 16
    70. 70. SBT & Android • http://github.com/jberkel/android-plugin scalac .class files 16
    71. 71. SBT & Android • http://github.com/jberkel/android-plugin scalac .class files ProGuard 16
    72. 72. SBT & Android • http://github.com/jberkel/android-plugin scalac .class files ProGuard 16
    73. 73. SBT & Android • http://github.com/jberkel/android-plugin scalac .class files less .class ProGuard files 16
    74. 74. SBT & Android • http://github.com/jberkel/android-plugin scalac .class files less .class ProGuard files 16
    75. 75. SBT & Android • http://github.com/jberkel/android-plugin scalac .class files less .class ProGuard files dx 16
    76. 76. SBT & Android • http://github.com/jberkel/android-plugin scalac .class files less .class ProGuard files dx 16
    77. 77. SBT & Android • http://github.com/jberkel/android-plugin scalac ... .class files less .class ProGuard files dx 16
    78. 78. Demo 17
    79. 79. SBT & Idea • http://github.com/mpeltonen/sbt-idea-plugin • Hacked to work with sbt-android-plugin: http://github.com/thoraage/sbt-idea-plugin • Generates project files • SBT processor 18
    80. 80. SBT & Eclipse • http://github.com/musk/SbtEclipsify • Not tested with Android 19
    81. 81. Scala on Androids Quick wins 20
    82. 82. Resources Resource xml’s and R.java 21
    83. 83. Layout definition <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:a="http://schemas.android.com/apk/res/android" ...> <TextView a:text="@string/host_address_text" .../> <EditText a:id="@+id/hostAddress" .../> <Button a:id="@+id/login" a:text="@string/login_button_text" .../> </LinearLayout> 22
    84. 84. Layout definition <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:a="http://schemas.android.com/apk/res/android" ...> <TextView a:text="@string/host_address_text" .../> <EditText a:id="@+id/hostAddress" .../> <Button a:id="@+id/login" a:text="@string/login_button_text" .../> </LinearLayout> 22
    85. 85. R.java public final class R { ... public static final class id { public static final int login=0x7f050001; } ... public static final class string { public static final int login_button_text=0x7f040003; } } 23
    86. 86. R.java public final class R { ... public static final class id { public static final int login=0x7f050001; } ... public static final class string { public static final int login_button_text=0x7f040003; } } 23
    87. 87. R.java public final class R { ... public static final class id { public static final int login=0x7f050001; } ... public static final class string { public static final int login_button_text=0x7f040003; } } 23
    88. 88. R.java Button? public final class R { ... public static final class id { public static final int login=0x7f050001; } ... public static final class string { public static final int login_button_text=0x7f040003; } } 23
    89. 89. R.java public final class R { ... public static final class id { public static final int login=0x7f050001; } ... public static final class string { public static final int login_button_text=0x7f040003; } } 23
    90. 90. R.java usage • In java • Button login = (Button) findViewById(R.id.login); 24
    91. 91. R.java usage • In java • Button login = (Button) findViewById(R.id.login); 24
    92. 92. R.java usage • In java • Button login = (Button) findViewById(R.id.login); 24
    93. 93. R.java usage • In java • Button login = (Button) findViewById(R.id.login); • In Scala • val login = findViewById(R.id.login).asInstanceOf[Button] 24
    94. 94. R.java usage • In java • Button login = (Button) findViewById(R.id.login); • In Scala • val login = findViewById(R.id.login).asInstanceOf[Button] 24
    95. 95. R.java usage • In java • Button login = (Button) findViewById(R.id.login); • In Scala • val login = findViewById(R.id.login).asInstanceOf[Button] 24
    96. 96. TR.scala ... object TR { val login = TypedResource[android.widget.Button](R.id.login) } ... trait TypedActivityHolder { def activity: Activity def findView[T](tr: TypedResource[T]) = activity.findViewById(tr.id).asInstanceOf[T] } trait TypedActivity extends Activity with TypedActivityHolder { def activity = this } 25
    97. 97. TR.scala ... object TR { val login = TypedResource[android.widget.Button](R.id.login) } ... trait TypedActivityHolder { def activity: Activity def findView[T](tr: TypedResource[T]) = activity.findViewById(tr.id).asInstanceOf[T] } trait TypedActivity extends Activity with TypedActivityHolder { def activity = this } 25
    98. 98. TR.scala ... object TR { val login = TypedResource[android.widget.Button](R.id.login) } ... trait TypedActivityHolder { def activity: Activity def findView[T](tr: TypedResource[T]) = activity.findViewById(tr.id).asInstanceOf[T] } trait TypedActivity extends Activity with TypedActivityHolder { def activity = this } 25
    99. 99. TR.scala ... object TR { val login = TypedResource[android.widget.Button](R.id.login) } ... trait TypedActivityHolder { def activity: Activity def findView[T](tr: TypedResource[T]) = activity.findViewById(tr.id).asInstanceOf[T] } trait TypedActivity extends Activity with TypedActivityHolder { def activity = this } 25
    100. 100. TR.scala ... object TR { val login = TypedResource[android.widget.Button](R.id.login) } ... trait TypedActivityHolder { def activity: Activity def findView[T](tr: TypedResource[T]) = activity.findViewById(tr.id).asInstanceOf[T] } trait TypedActivity extends Activity with TypedActivityHolder { def activity = this } 25
    101. 101. TR.scala ... object TR { val login = TypedResource[android.widget.Button](R.id.login) } ... trait TypedActivityHolder { def activity: Activity def findView[T](tr: TypedResource[T]) = activity.findViewById(tr.id).asInstanceOf[T] } trait TypedActivity extends Activity with TypedActivityHolder { def activity = this } 25
    102. 102. TR.java usage • With TR.scala • val login = findView(TR.login) 26
    103. 103. Listeners 27
    104. 104. Listeners login.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { ... } } 28
    105. 105. Listeners login.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { ... } } login.setOnClickListener(new View.OnClickListener() { override def onClick(view: View) { ... } }) 28
    106. 106. Scala 101 Anonymous functions class Printer[A](list: List[A]) { def printSome(p: A => Boolean): Unit = for (elem <- list) if (p(elem)) println(elem.toString) } 29
    107. 107. Scala 101 Anonymous functions class Printer[A](list: List[A]) { def printSome(p: A => Boolean): Unit = for (elem <- list) if (p(elem)) println(elem.toString) } 29
    108. 108. Scala 101 Anonymous functions class Printer[A](list: List[A]) { def printSome(p: A => Boolean): Unit = for (elem <- list) if (p(elem)) println(elem.toString) } 29
    109. 109. Scala 101 Anonymous functions class Printer[A](list: List[A]) { def printSome(p: A => Boolean): Unit = for (elem <- list) if (p(elem)) println(elem.toString) } 29
    110. 110. Scala 101 Anonymous functions class Printer[A](list: List[A]) { def printSome(p: A => Boolean): Unit = for (elem <- list) if (p(elem)) println(elem.toString) } 29
    111. 111. Scala 101 Anonymous functions class Printer[A](list: List[A]) { def printSome(p: A => Boolean): Unit = for (elem <- list) if (p(elem)) println(elem.toString) } val printer = new Printer(List("yo", "doh", "hi")) printer.printSome { e => e.contains("o") } 29
    112. 112. Scala 101 Anonymous functions class Printer[A](list: List[A]) { def printSome(p: A => Boolean): Unit = for (elem <- list) if (p(elem)) println(elem.toString) } val printer = new Printer(List("yo", "doh", "hi")) printer.printSome { e => e.contains("o") } 29
    113. 113. Scala 101 Anonymous functions class Printer[A](list: List[A]) { def printSome(p: A => Boolean): Unit = for (elem <- list) if (p(elem)) println(elem.toString) } val printer = new Printer(List("yo", "doh", "hi")) printer.printSome { e => e.contains("o") } 29
    114. 114. Scala 101 Anonymous functions class Printer[A](list: List[A]) { def printSome(p: A => Boolean): Unit = for (elem <- list) if (p(elem)) println(elem.toString) } val printer = new Printer(List("yo", "doh", "hi")) printer.printSome { e => e.contains("o") } 29
    115. 115. Scala 101 Anonymous functions class Printer[A](list: List[A]) { def printSome(p: A => Boolean): Unit = for (elem <- list) if (p(elem)) println(elem.toString) } val printer = new Printer(List("yo", "doh", "hi")) printer.printSome { e => e.contains("o") } 29
    116. 116. Scala 101 Anonymous functions class Printer[A](list: List[A]) { def printSome(p: A => Boolean): Unit = for (elem <- list) if (p(elem)) println(elem.toString) } val printer = new Printer(List("yo", "doh", "hi")) printer.printSome { e => e.contains("o") } printer.printSome(_.contains("o")) 29
    117. 117. Scala 101 Anonymous functions class Printer[A](list: List[A]) { def printSome(p: A => Boolean): Unit = for (elem <- list) if (p(elem)) println(elem.toString) } val printer = new Printer(List("yo", "doh", "hi")) printer.printSome { e => e.contains("o") } printer.printSome(_.contains("o")) 29
    118. 118. Listeners def onClick(f: View => Unit) { setOnClickListener(new View.OnClickListener { override def onClick(v: View) = f(v) }) } 30
    119. 119. Listeners def onClick(f: View => Unit) { setOnClickListener(new View.OnClickListener { override def onClick(v: View) = f(v) }) } 30
    120. 120. Listeners def onClick(f: View => Unit) { setOnClickListener(new View.OnClickListener { override def onClick(v: View) = f(v) }) } 30
    121. 121. Listeners def onClick(f: View => Unit) { setOnClickListener(new View.OnClickListener { override def onClick(v: View) = f(v) }) } login.onClick { view => ... } 30
    122. 122. Scala 101 Implicit conversion class AmendedString(s: String) { def rot13 = new String(for (c <- s) yield rotC(c)) def rotC(c: Char) = (((c - 97) + 13) % 26 + 97).asInstanceOf[Char] } 31
    123. 123. Scala 101 Implicit conversion class AmendedString(s: String) { def rot13 = new String(for (c <- s) yield rotC(c)) def rotC(c: Char) = (((c - 97) + 13) % 26 + 97).asInstanceOf[Char] } 31
    124. 124. Scala 101 Implicit conversion class AmendedString(s: String) { def rot13 = new String(for (c <- s) yield rotC(c)) def rotC(c: Char) = (((c - 97) + 13) % 26 + 97).asInstanceOf[Char] } 31
    125. 125. Scala 101 Implicit conversion class AmendedString(s: String) { def rot13 = new String(for (c <- s) yield rotC(c)) def rotC(c: Char) = (((c - 97) + 13) % 26 + 97).asInstanceOf[Char] } new AmendedString("yodude").rot13 31
    126. 126. Scala 101 Implicit conversion class AmendedString(s: String) { def rot13 = new String(for (c <- s) yield rotC(c)) def rotC(c: Char) = (((c - 97) + 13) % 26 + 97).asInstanceOf[Char] } new AmendedString("yodude").rot13 implicit def string2amendedString(s: String) = new AmendedString(s) 31
    127. 127. Scala 101 Implicit conversion class AmendedString(s: String) { def rot13 = new String(for (c <- s) yield rotC(c)) def rotC(c: Char) = (((c - 97) + 13) % 26 + 97).asInstanceOf[Char] } new AmendedString("yodude").rot13 implicit def string2amendedString(s: String) = new AmendedString(s) 31
    128. 128. Scala 101 Implicit conversion class AmendedString(s: String) { def rot13 = new String(for (c <- s) yield rotC(c)) def rotC(c: Char) = (((c - 97) + 13) % 26 + 97).asInstanceOf[Char] } new AmendedString("yodude").rot13 implicit def string2amendedString(s: String) = new AmendedString(s) 31
    129. 129. Scala 101 Implicit conversion class AmendedString(s: String) { def rot13 = new String(for (c <- s) yield rotC(c)) def rotC(c: Char) = (((c - 97) + 13) % 26 + 97).asInstanceOf[Char] } new AmendedString("yodude").rot13 implicit def string2amendedString(s: String) = new AmendedString(s) 31
    130. 130. Scala 101 Implicit conversion class AmendedString(s: String) { def rot13 = new String(for (c <- s) yield rotC(c)) def rotC(c: Char) = (((c - 97) + 13) % 26 + 97).asInstanceOf[Char] } new AmendedString("yodude").rot13 implicit def string2amendedString(s: String) = new AmendedString(s) "yodude".rot13 31
    131. 131. Scala 101 Implicit conversion class AmendedString(s: String) { def rot13 = new String(for (c <- s) yield rotC(c)) def rotC(c: Char) = (((c - 97) + 13) % 26 + 97).asInstanceOf[Char] } new AmendedString("yodude").rot13 implicit def string2amendedString(s: String) = new AmendedString(s) "yodude".rot13 31
    132. 132. Scala 101 Implicit conversion class AmendedString(s: String) { def rot13 = new String(for (c <- s) yield rotC(c)) def rotC(c: Char) = (((c - 97) + 13) % 26 + 97).asInstanceOf[Char] } new AmendedString("yodude").rot13 implicit def string2amendedString(s: String) = new AmendedString(s) "yodude".rot13 lbqhqr 31
    133. 133. Listeners class AmendedView(view: View) { def onClick(f: View => Unit) { view.setOnClickListener(new View.OnClickListener { override def onClick(v: View) = f(v) }) } } 32
    134. 134. Listeners class AmendedView(view: View) { def onClick(f: View => Unit) { view.setOnClickListener(new View.OnClickListener { override def onClick(v: View) = f(v) }) } } 32
    135. 135. Listeners class AmendedView(view: View) { def onClick(f: View => Unit) { view.setOnClickListener(new View.OnClickListener { override def onClick(v: View) = f(v) }) } } 32
    136. 136. Listeners class AmendedView(view: View) { def onClick(f: View => Unit) { view.setOnClickListener(new View.OnClickListener { override def onClick(v: View) = f(v) }) } } 32
    137. 137. Listeners class AmendedView(view: View) { def onClick(f: View => Unit) { view.setOnClickListener(new View.OnClickListener { override def onClick(v: View) = f(v) }) } } 32
    138. 138. Listeners class AmendedView(view: View) { def onClick(f: View => Unit) { view.setOnClickListener(new View.OnClickListener { override def onClick(v: View) = f(v) }) } } implicit def view2AmendedView(view: View) = new AmendedView(view) 32
    139. 139. Listeners class AmendedView(view: View) { def onClick(f: View => Unit) { view.setOnClickListener(new View.OnClickListener { override def onClick(v: View) = f(v) }) } } implicit def view2AmendedView(view: View) = new AmendedView(view) 32
    140. 140. Listeners class AmendedView(view: View) { def onClick(f: View => Unit) { view.setOnClickListener(new View.OnClickListener { override def onClick(v: View) = f(v) }) } } implicit def view2AmendedView(view: View) = new AmendedView(view) 32
    141. 141. Listeners class AmendedView(view: View) { def onClick(f: View => Unit) { view.setOnClickListener(new View.OnClickListener { override def onClick(v: View) = f(v) }) } } implicit def view2AmendedView(view: View) = new AmendedView(view) 32
    142. 142. Listeners class AmendedView(view: View) { def onClick(f: View => Unit) { view.setOnClickListener(new View.OnClickListener { override def onClick(v: View) = f(v) }) } } implicit def view2AmendedView(view: View) = new AmendedView(view) 32
    143. 143. Listeners class AmendedView(view: View) { def onClick(f: View => Unit) { view.setOnClickListener(new View.OnClickListener { override def onClick(v: View) = f(v) }) } } implicit def view2AmendedView(view: View) = new AmendedView(view) login.onClick { view => ... } 32
    144. 144. Concurrency 33
    145. 145. Responsiveness • Separate work and GUI GUI thread 34
    146. 146. Responsiveness • Separate work and GUI GUI thread 34
    147. 147. Responsiveness GUI thread worker Start worker 35
    148. 148. Responsiveness new AsyncTask[Object, Void, Object]() { override def doInBackground(objects: Object*): Object = { ... do hard work } }.execute() 36
    149. 149. Responsiveness new AsyncTask[Object, Void, Object]() { override def doInBackground(objects: Object*): Object = { ... do hard work } }.execute() 36
    150. 150. Responsiveness new AsyncTask[Object, Void, Object]() { override def doInBackground(objects: Object*): Object = { ... do hard work } }.execute() 36
    151. 151. Responsiveness new AsyncTask[Object, Void, Object]() { override def doInBackground(objects: Object*): Object = { ... do hard work } }.execute() 36
    152. 152. Responsiveness new AsyncTask[Object, Void, Object]() { override def doInBackground(objects: Object*): Object = { ... do hard work } }.execute() 36
    153. 153. Responsiveness new AsyncTask[Object, Void, Object]() { override def doInBackground(objects: Object*): Object = { ... do hard work } }.execute() 36
    154. 154. Responsiveness GUI thread worker Start worker Update GUI 37
    155. 155. Responsiveness runOnUiThread(new Runnable() { def run: Unit = { ... update GUI } }) 38
    156. 156. Responsiveness runOnUiThread(new Runnable() { def run: Unit = { ... update GUI } }) 38
    157. 157. Responsiveness runOnUiThread(new Runnable() { def run: Unit = { ... update GUI } }) 38
    158. 158. Responsiveness runOnUiThread(new Runnable() { def run: Unit = { ... update GUI } }) 38
    159. 159. Responsiveness runOnUiThread(new Runnable() { def run: Unit = { ... update GUI } }) 38
    160. 160. Responsiveness new AsyncTask[Object, Void, Object]() { override def doInBackground(objects: Object*): Object = { ... do hard work runOnUiThread(new Runnable() { def run: Unit = { ... update GUI } }) } }.execute() 39
    161. 161. Responsiveness new AsyncTask[Object, Void, Object]() { override def doInBackground(objects: Object*): Object = { ... do hard work runOnUiThread(new Runnable() { def run: Unit = { ... update GUI } }) } }.execute() 39
    162. 162. Responsiveness new AsyncTask[Object, Void, Object]() { override def doInBackground(objects: Object*): Object = { ... do hard work runOnUiThread(new Runnable() { def run: Unit = { ... update GUI } }) } }.execute() 39
    163. 163. Responsiveness new AsyncTask[Object, Void, Object]() { override def doInBackground(objects: Object*): Object = { ... do hard work runOnUiThread(new Runnable() { def run: Unit = { ... update GUI } }) } }.execute() 39
    164. 164. Responsiveness new AsyncTask[Object, Void, Object]() { override def doInBackground(objects: Object*): Object = { ... do hard work runOnUiThread(new Runnable() { def run: Unit = { ... update GUI } }) } }.execute() 39
    165. 165. Responsiveness new AsyncTask[Object, Void, Object]() { override def doInBackground(objects: Object*): Object = { ... do hard work runOnUiThread(new Runnable() { def run: Unit = { ... update GUI } }) } }.execute() 39
    166. 166. Responsiveness new AsyncTask[Object, Void, Object]() { override def doInBackground(objects: Object*): Object = { ... do hard work runOnUiThread(new Runnable() { def run: Unit = { ... update GUI } }) } }.execute() 39
    167. 167. Responsiveness new AsyncTask[Object, Void, Object]() { override def doInBackground(objects: Object*): Object = { ... do hard work runOnUiThread(new Runnable() { def run: Unit = { ... update GUI } }) } }.execute() 39
    168. 168. Responsiveness new AsyncTask[Object, Void, Object]() { override def doInBackground(objects: Object*): Object = { ... do hard work runOnUiThread(new Runnable() { def run: Unit = { ... update GUI } }) } }.execute() 39
    169. 169. Responsiveness new AsyncTask[Object, Void, Object]() { override def doInBackground(objects: Object*): Object = { ... do hard work onUiThread { ... update GUI } } }.execute() 40
    170. 170. Responsiveness asyncTask { ... do hard work onUiThread { ... update GUI } } 41
    171. 171. Further 42
    172. 172. Actors Organizing with asynchronous message passing 43
    173. 173. Scala 101 Actors object MyActor extends Actor { def act { loop { react { case msg:String => println(msg) case other => println("Say what") } } } start } 44
    174. 174. Scala 101 Actors object MyActor extends Actor { def act { loop { react { case msg:String => println(msg) case other => println("Say what") } } } start } 44
    175. 175. Scala 101 Actors object MyActor extends Actor { def act { loop { react { case msg:String => println(msg) case other => println("Say what") } } } start } 44
    176. 176. Scala 101 Actors object MyActor extends Actor { def act { loop { react { case msg:String => println(msg) case other => println("Say what") } } } start } 44
    177. 177. Scala 101 Actors object MyActor extends Actor { def act { loop { react { case msg:String => println(msg) case other => println("Say what") } } } start } 44
    178. 178. Scala 101 Actors object MyActor extends Actor { def act { loop { react { case msg:String => println(msg) case other => println("Say what") } } } start } 44
    179. 179. Scala 101 Actors object MyActor extends Actor { def act { loop { react { case msg:String => println(msg) case other => println("Say what") } } } start } 44
    180. 180. Scala 101 Actors object MyActor extends Actor { def act { loop { react { case msg:String => println(msg) case other => println("Say what") } } } start } 44
    181. 181. Scala 101 Actors object MyActor extends Actor { def act { loop { react { case msg:String => println(msg) case other => println("Say what") } } } start } 44
    182. 182. Scala 101 Actors object MyActor extends Actor { def act { loop { react { case msg:String => println(msg) case other => println("Say what") } } } start } 44
    183. 183. Scala 101 Actors object MyActor extends Actor { def act { loop { react { case msg:String => println(msg) case other => println("Say what") } } } start } 44
    184. 184. Scala 101 Actors object MyActor extends Actor { def act { loop { react { case msg:String => println(msg) case other => println("Say what") } } } start } 44
    185. 185. Scala 101 Actors object MyActor extends Actor { def act { loop { react { case msg:String => println(msg) case other => println("Say what") } } } start } 44
    186. 186. Scala 101 Actors object MyActor extends Actor { def act { loop { react { case msg:String => println(msg) case other => println("Say what") } } } start } 44
    187. 187. Scala 101 Actors object MyActor extends Actor { def act { loop { react { case msg:String => println(msg) case other => println("Say what") } } } start } MyActor ! "Yo dude" 44
    188. 188. Scala 101 Actors object MyActor extends Actor { def act { loop { react { case msg:String => println(msg) case other => println("Say what") } } } start } MyActor ! "Yo dude" 44
    189. 189. Scala 101 Actors object MyActor extends Actor { def act { loop { react { case msg:String => println(msg) case other => println("Say what") } } } start } MyActor ! "Yo dude" 44
    190. 190. Scala 101 Actors object MyActor extends Actor { def act { loop { react { case msg:String => println(msg) case other => println("Say what") } } } start } MyActor ! "Yo dude" 44
    191. 191. Scala 101 Actors object MyActor extends Actor { def act { loop { react { case msg:String => println(msg) case other => println("Say what") } } } start } MyActor ! "Yo dude" Yo dude 44
    192. 192. Actors GUI Connection Model Factory ViewStack href, (xml, error) httperror, none xml, (model, error) xmlerror, none model, (model) model, none 45
    193. 193. Actors GUI Connection Model Factory ViewStack href, (xml, error) httperror, none xml, (model, error) xmlerror, none model, (model) model, none 45
    194. 194. Actors GUI Connection Model Factory ViewStack href, (xml, error) httperror, none xml, (model, error) xmlerror, none model, (model) model, none 45
    195. 195. Actors GUI Connection Model Factory ViewStack href, (xml, error) httperror, none xml, (model, error) xmlerror, none model, (model) model, none 45
    196. 196. Actors GUI Connection Model Factory ViewStack href, (xml, error) httperror, none xml, (model, error) xmlerror, none model, (model) model, none 45
    197. 197. Actors GUI Connection Model Factory ViewStack href, (xml, error) httperror, none xml, (model, error) xmlerror, none model, (model) model, none 45
    198. 198. Actors GUI Connection Model Factory ViewStack href, (xml, error) httperror, none xml, (model, error) xmlerror, none model, (model) model, none 45
    199. 199. Actors GUI Connection Model Factory ViewStack href, (xml, error) httperror, none xml, (model, error) xmlerror, none model, (model) model, none 45
    200. 200. Actors GUI Connection Model Factory ViewStack href, (xml, error) httperror, none xml, (model, error) xmlerror, none model, (model) model, none 45
    201. 201. Actors GUI Connection Model Factory ViewStack href, (xml, error) httperror, none xml, (model, error) xmlerror, none model, (model) model, none 45
    202. 202. Actors GUI Connection Model Factory ViewStack href, (xml, error) httperror, none xml, (model, error) xmlerror, none model, (model) model, none 45
    203. 203. Actors GUI Connection Model Factory ViewStack href, (xml, error) httperror, none xml, (model, error) xmlerror, none model, (model) model, none 45
    204. 204. Actors GUI Connection Model Factory ViewStack href, (xml, error) httperror, none xml, (model, error) xmlerror, none model, (model) model, none 45
    205. 205. Actors GUI Connection Model Factory ViewStack href, (xml, error) httperror, none xml, (model, error) xmlerror, none model, (model) model, none 45
    206. 206. Actors GUI Connection Model Factory ViewStack href, (xml, error) httperror, none xml, (model, error) xmlerror, none model, (model) model, none 45
    207. 207. Actors case class Routing(success: Option[Actor], failure: Option[Actor]) case class HttpRequestMsg(href: URL, routing: Routing) 46
    208. 208. Actors case class Routing(success: Option[Actor], failure: Option[Actor]) case class HttpRequestMsg(href: URL, routing: Routing) 46
    209. 209. Actors case class Routing(success: Option[Actor], failure: Option[Actor]) case class HttpRequestMsg(href: URL, routing: Routing) 46
    210. 210. Actors case class Routing(success: Option[Actor], failure: Option[Actor]) case class HttpRequestMsg(href: URL, routing: Routing) 46
    211. 211. Actors case class Routing(success: Option[Actor], failure: Option[Actor]) case class HttpRequestMsg(href: URL, routing: Routing) 46
    212. 212. Actors case class Routing(success: Option[Actor], failure: Option[Actor]) case class HttpRequestMsg(href: URL, routing: Routing) 46
    213. 213. Actors case class Routing(success: Option[Actor], failure: Option[Actor]) case class HttpRequestMsg(href: URL, routing: Routing) 46
    214. 214. Actors case class Routing(success: Option[Actor], failure: Option[Actor]) case class HttpRequestMsg(href: URL, routing: Routing) 46
    215. 215. Actors case class Routing(success: Option[Actor], failure: Option[Actor]) case class HttpRequestMsg(href: URL, routing: Routing) 46
    216. 216. Actors case class Routing(success: Option[Actor], failure: Option[Actor]) case class HttpRequestMsg(href: URL, routing: Routing) 46
    217. 217. Actors case class Routing(success: Option[Actor], failure: Option[Actor]) case class HttpRequestMsg(href: URL, routing: Routing) 46
    218. 218. Actors case class Routing(success: Option[Actor], failure: Option[Actor]) case class HttpRequestMsg(href: URL, routing: Routing) retrieveData.onClick { Connection ! new HttpRequestMsg( "http://s.no/dig/url", new Routing(Some(ModelFactory), Some(GUI))) } 46
    219. 219. Actors case class Routing(success: Option[Actor], failure: Option[Actor]) case class HttpRequestMsg(href: URL, routing: Routing) retrieveData.onClick { Connection ! new HttpRequestMsg( "http://s.no/dig/url", new Routing(Some(ModelFactory), Some(GUI))) } 46
    220. 220. Actors case class Routing(success: Option[Actor], failure: Option[Actor]) case class HttpRequestMsg(href: URL, routing: Routing) retrieveData.onClick { Connection ! new HttpRequestMsg( "http://s.no/dig/url", new Routing(Some(ModelFactory), Some(GUI))) } 46
    221. 221. Actors case class Routing(success: Option[Actor], failure: Option[Actor]) case class HttpRequestMsg(href: URL, routing: Routing) retrieveData.onClick { Connection ! new HttpRequestMsg( "http://s.no/dig/url", new Routing(Some(ModelFactory), Some(GUI))) } 46
    222. 222. Actors case class Routing(success: Option[Actor], failure: Option[Actor]) case class HttpRequestMsg(href: URL, routing: Routing) retrieveData.onClick { Connection ! new HttpRequestMsg( "http://s.no/dig/url", new Routing(Some(ModelFactory), Some(GUI))) } 46
    223. 223. Actors case class Routing(success: Option[Actor], failure: Option[Actor]) case class HttpRequestMsg(href: URL, routing: Routing) retrieveData.onClick { Connection ! new HttpRequestMsg( "http://s.no/dig/url", new Routing(Some(ModelFactory), Some(GUI))) } 46
    224. 224. Actors case class Routing(success: Option[Actor], failure: Option[Actor]) case class HttpRequestMsg(href: URL, routing: Routing) retrieveData.onClick { Connection ! new HttpRequestMsg( "http://s.no/dig/url", new Routing(Some(ModelFactory), Some(GUI))) } 46
    225. 225. Actors case class Routing(success: Option[Actor], failure: Option[Actor]) case class HttpRequestMsg(href: URL, routing: Routing) retrieveData.onClick { Connection ! new HttpRequestMsg( "http://s.no/dig/url", new Routing(Some(ModelFactory), Some(GUI))) } 46
    226. 226. Actors case class Routing(success: Option[Actor], failure: Option[Actor]) case class HttpRequestMsg(href: URL, routing: Routing) retrieveData.onClick { Connection ! new HttpRequestMsg( "http://s.no/dig/url", new Routing(Some(ModelFactory), Some(GUI))) } 46
    227. 227. Actors case class Routing(success: Option[Actor], failure: Option[Actor]) case class HttpRequestMsg(href: URL, routing: Routing) retrieveData.onClick { Connection ! new HttpRequestMsg( "http://s.no/dig/url", new Routing(Some(ModelFactory), Some(GUI))) } 46
    228. 228. Actors case class Routing(success: Option[Actor], failure: Option[Actor]) case class HttpRequestMsg(href: URL, routing: Routing) retrieveData.onClick { Connection ! new HttpRequestMsg( "http://s.no/dig/url", new Routing(Some(ModelFactory), Some(GUI))) } 46
    229. 229. Actors case class Routing(success: Option[Actor], failure: Option[Actor]) case class HttpRequestMsg(href: URL, routing: Routing) retrieveData.onClick { Connection ! new HttpRequestMsg( "http://s.no/dig/url", new Routing(Some(ModelFactory), Some(GUI))) } 46
    230. 230. Actors case class Routing(success: Option[Actor], failure: Option[Actor]) case class HttpRequestMsg(href: URL, routing: Routing) retrieveData.onClick { Connection ! new HttpRequestMsg( "http://s.no/dig/url", new Routing(Some(ModelFactory), Some(GUI))) } 46
    231. 231. Actor object Connection extends Actor { def retrieve(href: String): Either[Node, Failure] = Right(new Failure()) def act { loop { react { case HttpRequestMsg(href, Routing(success, failure)) => retrieve(href) match { case Left(node) => success.map(_ ! node) case Right(error) => failure.map(_ ! error) } case _ => println("Say what") } } } start } 47
    232. 232. Actor object Connection extends Actor { def retrieve(href: String): Either[Node, Failure] = Right(new Failure()) def act { loop { react { case HttpRequestMsg(href, Routing(success, failure)) => retrieve(href) match { case Left(node) => success.map(_ ! node) case Right(error) => failure.map(_ ! error) } case _ => println("Say what") } } } start } 47
    233. 233. Actor object Connection extends Actor { def retrieve(href: String): Either[Node, Failure] = Right(new Failure()) def act { loop { react { case HttpRequestMsg(href, Routing(success, failure)) => retrieve(href) match { case Left(node) => success.map(_ ! node) case Right(error) => failure.map(_ ! error) } case _ => println("Say what") } } } start } 47
    234. 234. Actor object Connection extends Actor { def retrieve(href: String): Either[Node, Failure] = Right(new Failure()) def act { loop { react { case HttpRequestMsg(href, Routing(success, failure)) => retrieve(href) match { case Left(node) => success.map(_ ! node) case Right(error) => failure.map(_ ! error) } case _ => println("Say what") } } } start } 47
    235. 235. Actor object Connection extends Actor { def retrieve(href: String): Either[Node, Failure] = Right(new Failure()) def act { loop { react { case HttpRequestMsg(href, Routing(success, failure)) => retrieve(href) match { case Left(node) => success.map(_ ! node) case Right(error) => failure.map(_ ! error) } case _ => println("Say what") } } } start } 47
    236. 236. Actor object Connection extends Actor { def retrieve(href: String): Either[Node, Failure] = Right(new Failure()) def act { loop { react { case HttpRequestMsg(href, Routing(success, failure)) => retrieve(href) match { case Left(node) => success.map(_ ! node) case Right(error) => failure.map(_ ! error) } case _ => println("Say what") } } } start } 47
    237. 237. Actor object Connection extends Actor { def retrieve(href: String): Either[Node, Failure] = Right(new Failure()) def act { loop { react { case HttpRequestMsg(href, Routing(success, failure)) => retrieve(href) match { case Left(node) => success.map(_ ! node) case Right(error) => failure.map(_ ! error) } case _ => println("Say what") } } } start } 47
    238. 238. Actor object Connection extends Actor { def retrieve(href: String): Either[Node, Failure] = Right(new Failure()) def act { loop { react { case HttpRequestMsg(href, Routing(success, failure)) => retrieve(href) match { case Left(node) => success.map(_ ! node) case Right(error) => failure.map(_ ! error) } case _ => println("Say what") } } } start } 47
    239. 239. Actor object Connection extends Actor { def retrieve(href: String): Either[Node, Failure] = Right(new Failure()) def act { loop { react { case HttpRequestMsg(href, Routing(success, failure)) => retrieve(href) match { case Left(node) => success.map(_ ! node) case Right(error) => failure.map(_ ! error) } case _ => println("Say what") } } } start } 47
    240. 240. Actor object Connection extends Actor { def retrieve(href: String): Either[Node, Failure] = Right(new Failure()) def act { loop { react { case HttpRequestMsg(href, Routing(success, failure)) => retrieve(href) match { case Left(node) => success.map(_ ! node) case Right(error) => failure.map(_ ! error) } case _ => println("Say what") } } } start } 47
    241. 241. Actor object Connection extends Actor { def retrieve(href: String): Either[Node, Failure] = Right(new Failure()) def act { loop { react { case HttpRequestMsg(href, Routing(success, failure)) => retrieve(href) match { case Left(node) => success.map(_ ! node) case Right(error) => failure.map(_ ! error) } case _ => println("Say what") } } } start } 47
    242. 242. Actor object Connection extends Actor { def retrieve(href: String): Either[Node, Failure] = Right(new Failure()) def act { loop { react { case HttpRequestMsg(href, Routing(success, failure)) => retrieve(href) match { case Left(node) => success.map(_ ! node) case Right(error) => failure.map(_ ! error) } case _ => println("Say what") } } } start } 47
    243. 243. Actor object Connection extends Actor { def retrieve(href: String): Either[Node, Failure] = Right(new Failure()) def act { loop { react { case HttpRequestMsg(href, Routing(success, failure)) => retrieve(href) match { case Left(node) => success.map(_ ! node) case Right(error) => failure.map(_ ! error) } case _ => println("Say what") } } } start } 47
    244. 244. Androids on Scala Fini @thoraageeldby 48
    1. A particular slide catching your eye?

      Clipping is a handy way to collect important slides you want to go back to later.

    ×