SlideShare a Scribd company logo
1 of 39
Download to read offline
Scala
2011 10⽉月17⽇日
JJUG, Lab
•  Object-Oriented Programming (OOP)   Object-
   Functional Programming (OFP)
  • 
  • 
  • 
⾃自⼰己
•  ⽇日 Java                    ⻑⾧長 ( ) Lab
• 
   •  XML SmartDoc (XML⽂文                  )
   •  Relaxer (XML/Java                   )
• 
   •  SimpleModeler (Scala DSL                 )
   •  g3 (                                   )
   •  g4 (Android             )
• 
   •        ⼯工 UML              (⽇日 BP)
   •                                            (   )
   •            Scala (Softbank Creative)
•  Modegramming Style (           DSL
           )
  •  http://modegramming.blogspot.com/
•  SimpleModeler
  •  http://code.google.com/p/simplemodeler/
•  g3
  •  http://code.google.com/p/goldenport3/
•  g4
  •  https://github.com/asami/goldenport-android-library
SCALA   ⾔言
Scala
Scala ⽤用
• ⾼高            ⽣生
     •               3
• DSL (Domain Specific Language)
     • 
     •                   API
•         ⾏行行
     •  Many Core
     •  Parallel Everything
⾔言
•  ⾼高
     • 
     • 




•         (        )
⾔言                   ⻑⾧長
•  ⻑⾧長
     •  ⾼高
          •  List,                  (         )
     • 
          •                (                  )   (     )
                                        (          ⼊入       )
• 
     •           ⾏行行
          • 
     •               ⼤大
          • 
          •               ⼤大
     •                         ⽤用
          • 
⾔言
•                   ⾔言     •                     ⾔言
     •  pure Lisp               •  Haskell
     •                          •  Scala(+scalaz)
•                     ⾔言        • 
     •  Lisp, ML, OCaml              • 

     •                               •  Parametric
     •  ⼿手                              polymorphism
                                • 
       •                        • 
       •  Subtype
          polymorphism
DSL (Domain Specific Language)
•            ⾔言                  DSL
     •  ⾼高
•  Scala DSL         ⽅方
     •  JJUG CCC 2010 Fall
     •  http://www.slideshare.net/asami224/scala-dsl
val CNN = "http://www.cnn.com"!
val YAHOO = "http://www.yahoo.com"!
val AMAZON = "http://www.amazon.com"!
!
def sitelen(url: String): Int = {!
   import scala.io.Source!
   val source = scala.io.Source.fromURL(url)!
   source.getLines.map(_.length).sum!
}!




scala> sitelen(CNN)!
res92: Int = 85569
List(CNN, YAHOO, AMAZON).map(sitelen).sum

        ⾏行行    6.3    (scala.testing.Benchmark       )


List(CNN, YAHOO, AMAZON).par.map(sitelen).sum


        ⾏行行    2     (scala.testing.Benchmark    )
Future
•               ⾮非         ⾏行行     ⾏行行

     •               ⾏行行                         ⾏行行
     •    ⾏行行                    ⾏行行                           ⾏行行

•  Java                                     (java.util.concurrent)

•  Scala                                 (scala.actors)

•                          Future         ⾏行行
import java.util.concurrent._!
!
val e = Executors.newSingleThreadExecutor!
val f: Future[Int] = e.submit(!
  new Callable[Int] {!
    def call() = {!
       sitelen(CNN)!
    }!
  })!
!
f.get!




import scala.actors.Futures._!
!
val length = future { sitelen(CNN) }!
length()!
Promise
•               ⾮非         ⾏行行     ⾏行行

     •               ⾏行行                      ⾏行行
     •    ⾏行行                    ⾏行行                      ⾏行行

•  Future
     •                                   ⾮非         ⾏行行
import scalaz._!
import Scalaz._!
!
// def sitelen(url: String): Int = ...!
def sizekind(len: Int) = {!
   if (len > 10000) "Large" !
   else "Small"!
}!
def sitelenpromise = (sitelen _).promise!
def sizekindpromise = (sizekind _).promise!
def sitekindpromise = {!
   sitelenpromise >=> sizekindpromise!
}!



scala> val p = sitekindpromise(CNN)!
res105: scalaz.concurrent.Promise
[java.lang.String] = <promise>!
scala> p.get!
res107: java.lang.String = Large!
5
1: y = f(x)
• 
• 
     •                  ⼤大
def add1(a: Int): Int = a + 1
   add1       (Int) => Int

scala> add1(3)!
res84: Int = 4

scala> List(1, 2, 3).map(add1)!
res83: List[Int] = List(2, 3, 4)


def add(a: Int, b: Int): Int = a + b
  addx       (Int, Int) => Int
scala> List(1, 2, 3).map(add)!
<console>:34: error: type mismatch;!
 found   : (Int, Int) => Int!
 required: (Int) => ?!
       List(1, 2, 3).map(add)!
                         ^!
def addc(a: Int)(b: Int): Int = a + b


  addc       (Int) => (Int) => Int
  Int          (Int) => Int



scala> val x = List(1, 2, 3).map(addc)!
res87: List[(Int) => Int] = List
(<function1>, <function1>, <function1>)!

scala> x.map(f => f(1))!
res89: List[Int] = List(2, 3, 4)!
2:
• 
• 
•               ⼩小
•    ⾏行行
case class        ()!
case class            1()!
case class            2()!
case class        (        1:        1, !
                           2:        2)!
!
def          1      (a:      ) =        1()!
def          2      (a:      ) =        2()!
!
def            (a:      ):      = {!
      (         1      (a),!
                 2      (a))!
}!
def qsort(a: List[Int]): List[Int] = {!
   a match {!
      case Nil => Nil!
      case List(a) => List(a)!
      case List(a, b) => if (a < b) List(a, b) !
                          else List(b, a)!
      case _ => {!
         val small = a.filter(_ < a.head)!
         val large = a.filter(_ > a.head)!
         qsort(small) ::: List(a.head) ::: qsort(large)!
      }!
   }!
}!



scala> qsort(List(10, 3, 8, 5, 2, 6))!
res142: List[Int] = List(2, 3, 5, 6, 8, 10)!
3:
def zeroonetwo(a: Int): List[Int] = {!
  List(a, a + 1, a + 2)!
}


  map

scala> List(1, 2, 3).map(zeroonetwo)!
res138: List[List[Int]] = !
List(List(1, 2, 3), List(2, 3, 4), List(3, 4, 5))


  flatMap

scala> List(1, 2, 3).flatMap(zeroonetwo)!
res139: List[Int] = List(1, 2, 3, 2, 3, 4, 3, 4,
5)
foldLeft

def partition5(l: List[Int]) = {!
   l.foldLeft((List[Int](), List[Int]())) { (xs, x) =>!
      val (lhs, rhs) = xs!
      if (x > 5) (lhs, x :: rhs) else (x :: lhs, rhs)!
   }!
}!

def partition5(l: List[Int]) = {!
   ((List[Int](), List[Int]()) /: l) { (xs, x) =>!
      val (lhs, rhs) = xs!
      if (x > 5) (lhs, x :: rhs) else (x :: lhs, rhs)!
   }!
}!


scala> partition5(List(10, 3, 8, 5, 2, 6))!
res130: (List[Int], List[Int]) = !
(List(2, 5, 3),List(6, 8, 10))!
4:
•                   (referential transparency)
     •             ⾔言            ⼀一     ⽂文
                                                                ⾔言
               (Wikipedia)
•                       (persistent data structure)
     • 

                                                           ⽣生
                                                           ⽤用
               (Wikipedia)
•  Scala
   •  Value
   •                     scala.collection.immutable
   •                 case class ⽤用
          •  OOP                        DTO   case class
case class Person(name: String, email: String)!
case class Party(name: String, persons: List[Person])!
!
val party = Party(!
  "hobby",!
   List(Person("Taro", "taro@example.com"),!
        Person("Hanako", "hanako@example.com")))!
⽤用
•    ⼿手
• 
• 
• 
5:
•  ⾼高                                   ⼤大
     •    Functor ( ⼿手)
     •    Subgroup (      )
     •    Monoid (          )
     •    Monad (       )
     •          ⾊色
•            (           )
     •  ⾼高
     • 
•  OOP
     •  Visitor, AbstractFactory, TemplateMethod, Memento
     •         ⾊色
Functor

List(CNN, YAHOO, AMAZON).map(sitelen)

List(86076, 166806, 98089)!

 Monad

for (x <- List(1, 2, 3);!
     y <- List(10, 20, 30)) yield x * y

List(10, 20, 30, 20, 40, 60, 30, 60, 90)!

 Applicative Functor

import scalaz._!
import Scalaz._!
List(10, 20, 30) <*> (List(1, 2, 3) <*>!
 ((_: Int) * (_: Int)).curried.pure[List])

List(10, 20, 30, 20, 40, 60, 30, 60, 90)!
•    1: y = f(x)
•    2:
•    3:
•    4:
•    5:
END

More Related Content

What's hot

Miles Sabin Introduction To Scala For Java Developers
Miles Sabin Introduction To Scala For Java DevelopersMiles Sabin Introduction To Scala For Java Developers
Miles Sabin Introduction To Scala For Java Developers
Skills Matter
 
Taxonomy of Scala
Taxonomy of ScalaTaxonomy of Scala
Taxonomy of Scala
shinolajla
 
An Introduction to Scala
An Introduction to ScalaAn Introduction to Scala
An Introduction to Scala
Brent Lemons
 
Introduction to Functional Programming with Scala
Introduction to Functional Programming with ScalaIntroduction to Functional Programming with Scala
Introduction to Functional Programming with Scala
pramode_ce
 
Unraveling the mystery of monads
Unraveling the mystery of monadsUnraveling the mystery of monads
Unraveling the mystery of monads
Faisal Waris
 

What's hot (18)

Miles Sabin Introduction To Scala For Java Developers
Miles Sabin Introduction To Scala For Java DevelopersMiles Sabin Introduction To Scala For Java Developers
Miles Sabin Introduction To Scala For Java Developers
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to Scala
 
Scala basic
Scala basicScala basic
Scala basic
 
Static or Dynamic Typing? Why not both?
Static or Dynamic Typing? Why not both?Static or Dynamic Typing? Why not both?
Static or Dynamic Typing? Why not both?
 
Taxonomy of Scala
Taxonomy of ScalaTaxonomy of Scala
Taxonomy of Scala
 
Quick introduction to scala
Quick introduction to scalaQuick introduction to scala
Quick introduction to scala
 
An Introduction to Scala
An Introduction to ScalaAn Introduction to Scala
An Introduction to Scala
 
Scala: Object-Oriented Meets Functional, by Iulian Dragos
Scala: Object-Oriented Meets Functional, by Iulian DragosScala: Object-Oriented Meets Functional, by Iulian Dragos
Scala: Object-Oriented Meets Functional, by Iulian Dragos
 
10 Things I Hate About Scala
10 Things I Hate About Scala10 Things I Hate About Scala
10 Things I Hate About Scala
 
Introduction to Functional Programming with Scala
Introduction to Functional Programming with ScalaIntroduction to Functional Programming with Scala
Introduction to Functional Programming with Scala
 
Scala, Play 2.0 & Cloud Foundry
Scala, Play 2.0 & Cloud FoundryScala, Play 2.0 & Cloud Foundry
Scala, Play 2.0 & Cloud Foundry
 
Scala fundamentals
Scala fundamentalsScala fundamentals
Scala fundamentals
 
A brief tour of modern Java
A brief tour of modern JavaA brief tour of modern Java
A brief tour of modern Java
 
Scala intro for Java devs 20150324
Scala intro for Java devs 20150324Scala intro for Java devs 20150324
Scala intro for Java devs 20150324
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to Scala
 
Unraveling the mystery of monads
Unraveling the mystery of monadsUnraveling the mystery of monads
Unraveling the mystery of monads
 
SE 20016 - programming languages landscape.
SE 20016 - programming languages landscape.SE 20016 - programming languages landscape.
SE 20016 - programming languages landscape.
 
Ruby1_full
Ruby1_fullRuby1_full
Ruby1_full
 

Viewers also liked

Object-Funcational Analysis and design
Object-Funcational Analysis and designObject-Funcational Analysis and design
Object-Funcational Analysis and design
Tomoharu ASAMI
 
MindmapModelingチュートリアル
MindmapModelingチュートリアルMindmapModelingチュートリアル
MindmapModelingチュートリアル
Tomoharu ASAMI
 
オブジェクト指向開発におけるObject-Functional Programming
オブジェクト指向開発におけるObject-Functional Programmingオブジェクト指向開発におけるObject-Functional Programming
オブジェクト指向開発におけるObject-Functional Programming
Tomoharu ASAMI
 
Scalaプログラミング・マニアックス
Scalaプログラミング・マニアックスScalaプログラミング・マニアックス
Scalaプログラミング・マニアックス
Tomoharu ASAMI
 
実務者のためのかんたんScalaz
実務者のためのかんたんScalaz実務者のためのかんたんScalaz
実務者のためのかんたんScalaz
Tomoharu ASAMI
 

Viewers also liked (15)

Object-Funcational Analysis and design
Object-Funcational Analysis and designObject-Funcational Analysis and design
Object-Funcational Analysis and design
 
Monadicプログラミング マニアックス
Monadicプログラミング マニアックスMonadicプログラミング マニアックス
Monadicプログラミング マニアックス
 
モデリングの未来 〜~パネルディスカッション
モデリングの未来 〜~パネルディスカッションモデリングの未来 〜~パネルディスカッション
モデリングの未来 〜~パネルディスカッション
 
RDSDataSource: App Thinning
RDSDataSource: App ThinningRDSDataSource: App Thinning
RDSDataSource: App Thinning
 
Object-Functional Analysis and Design and Programming温泉
Object-Functional Analysis and Design and Programming温泉Object-Functional Analysis and Design and Programming温泉
Object-Functional Analysis and Design and Programming温泉
 
MindmapModelingチュートリアル
MindmapModelingチュートリアルMindmapModelingチュートリアル
MindmapModelingチュートリアル
 
オブジェクト指向開発におけるObject-Functional Programming
オブジェクト指向開発におけるObject-Functional Programmingオブジェクト指向開発におけるObject-Functional Programming
オブジェクト指向開発におけるObject-Functional Programming
 
Scalaプログラミング・マニアックス
Scalaプログラミング・マニアックスScalaプログラミング・マニアックス
Scalaプログラミング・マニアックス
 
Play勉強会 第3回
Play勉強会 第3回Play勉強会 第3回
Play勉強会 第3回
 
Androidオールスターズ2016 yanzm
Androidオールスターズ2016 yanzmAndroidオールスターズ2016 yanzm
Androidオールスターズ2016 yanzm
 
実務者のためのかんたんScalaz
実務者のためのかんたんScalaz実務者のためのかんたんScalaz
実務者のためのかんたんScalaz
 
なるべくコードを書かないAndroid開発
なるべくコードを書かないAndroid開発なるべくコードを書かないAndroid開発
なるべくコードを書かないAndroid開発
 
Prefer Cloud Platform - ビジョン、アーキテクチャ
Prefer Cloud Platform - ビジョン、アーキテクチャPrefer Cloud Platform - ビジョン、アーキテクチャ
Prefer Cloud Platform - ビジョン、アーキテクチャ
 
Monadic Programmingのススメ - Functional Reactive Programmingへのアプローチ
Monadic Programmingのススメ - Functional Reactive ProgrammingへのアプローチMonadic Programmingのススメ - Functional Reactive Programmingへのアプローチ
Monadic Programmingのススメ - Functional Reactive Programmingへのアプローチ
 
はじめようlocalization
はじめようlocalizationはじめようlocalization
はじめようlocalization
 

Similar to 楽々Scalaプログラミング

(How) can we benefit from adopting scala?
(How) can we benefit from adopting scala?(How) can we benefit from adopting scala?
(How) can we benefit from adopting scala?
Tomasz Wrobel
 
Scala In The Wild
Scala In The WildScala In The Wild
Scala In The Wild
djspiewak
 
Learning notes of r for python programmer (Temp1)
Learning notes of r for python programmer (Temp1)Learning notes of r for python programmer (Temp1)
Learning notes of r for python programmer (Temp1)
Chia-Chi Chang
 
From Lisp to Clojure/Incanter and RAn Introduction
From Lisp to Clojure/Incanter and RAn IntroductionFrom Lisp to Clojure/Incanter and RAn Introduction
From Lisp to Clojure/Incanter and RAn Introduction
elliando dias
 
Effective Scala (JavaDay Riga 2013)
Effective Scala (JavaDay Riga 2013)Effective Scala (JavaDay Riga 2013)
Effective Scala (JavaDay Riga 2013)
mircodotta
 

Similar to 楽々Scalaプログラミング (20)

Scala @ TechMeetup Edinburgh
Scala @ TechMeetup EdinburghScala @ TechMeetup Edinburgh
Scala @ TechMeetup Edinburgh
 
Scala in Places API
Scala in Places APIScala in Places API
Scala in Places API
 
(How) can we benefit from adopting scala?
(How) can we benefit from adopting scala?(How) can we benefit from adopting scala?
(How) can we benefit from adopting scala?
 
Osd ctw spark
Osd ctw sparkOsd ctw spark
Osd ctw spark
 
Scala In The Wild
Scala In The WildScala In The Wild
Scala In The Wild
 
Scala: Functioneel programmeren in een object georiënteerde wereld
Scala: Functioneel programmeren in een object georiënteerde wereldScala: Functioneel programmeren in een object georiënteerde wereld
Scala: Functioneel programmeren in een object georiënteerde wereld
 
Scala introduction
Scala introductionScala introduction
Scala introduction
 
sbt, history of JSON libraries, microservices, and schema evolution (Tokyo ver)
sbt, history of JSON libraries, microservices, and schema evolution (Tokyo ver)sbt, history of JSON libraries, microservices, and schema evolution (Tokyo ver)
sbt, history of JSON libraries, microservices, and schema evolution (Tokyo ver)
 
Scala on Android
Scala on AndroidScala on Android
Scala on Android
 
Learning notes of r for python programmer (Temp1)
Learning notes of r for python programmer (Temp1)Learning notes of r for python programmer (Temp1)
Learning notes of r for python programmer (Temp1)
 
From Lisp to Clojure/Incanter and RAn Introduction
From Lisp to Clojure/Incanter and RAn IntroductionFrom Lisp to Clojure/Incanter and RAn Introduction
From Lisp to Clojure/Incanter and RAn Introduction
 
Coscup
CoscupCoscup
Coscup
 
Effective Scala (JavaDay Riga 2013)
Effective Scala (JavaDay Riga 2013)Effective Scala (JavaDay Riga 2013)
Effective Scala (JavaDay Riga 2013)
 
Scala collections api expressivity and brevity upgrade from java
Scala collections api  expressivity and brevity upgrade from javaScala collections api  expressivity and brevity upgrade from java
Scala collections api expressivity and brevity upgrade from java
 
Speaking Scala: Refactoring for Fun and Profit (Workshop)
Speaking Scala: Refactoring for Fun and Profit (Workshop)Speaking Scala: Refactoring for Fun and Profit (Workshop)
Speaking Scala: Refactoring for Fun and Profit (Workshop)
 
R for Pirates. ESCCONF October 27, 2011
R for Pirates. ESCCONF October 27, 2011R for Pirates. ESCCONF October 27, 2011
R for Pirates. ESCCONF October 27, 2011
 
Hadoop london
Hadoop londonHadoop london
Hadoop london
 
Json the-x-in-ajax1588
Json the-x-in-ajax1588Json the-x-in-ajax1588
Json the-x-in-ajax1588
 
OCF.tw's talk about "Introduction to spark"
OCF.tw's talk about "Introduction to spark"OCF.tw's talk about "Introduction to spark"
OCF.tw's talk about "Introduction to spark"
 
Ruslan.shevchenko: most functional-day-kiev 2014
Ruslan.shevchenko: most functional-day-kiev 2014Ruslan.shevchenko: most functional-day-kiev 2014
Ruslan.shevchenko: most functional-day-kiev 2014
 

More from Tomoharu ASAMI

More from Tomoharu ASAMI (20)

アプリケーション・アーキテクチャ 【クラウドアプリケーションのためのオブジェクト指向分析設計講座 第34回】
アプリケーション・アーキテクチャ 【クラウドアプリケーションのためのオブジェクト指向分析設計講座 第34回】アプリケーション・アーキテクチャ 【クラウドアプリケーションのためのオブジェクト指向分析設計講座 第34回】
アプリケーション・アーキテクチャ 【クラウドアプリケーションのためのオブジェクト指向分析設計講座 第34回】
 
テスト 【クラウドアプリケーションのためのオブジェクト指向分析設計講座 第33回】
テスト 【クラウドアプリケーションのためのオブジェクト指向分析設計講座 第33回】テスト 【クラウドアプリケーションのためのオブジェクト指向分析設計講座 第33回】
テスト 【クラウドアプリケーションのためのオブジェクト指向分析設計講座 第33回】
 
実装(3) 【クラウドアプリケーションのためのオブジェクト指向分析設計講座 第32回】
実装(3) 【クラウドアプリケーションのためのオブジェクト指向分析設計講座 第32回】実装(3) 【クラウドアプリケーションのためのオブジェクト指向分析設計講座 第32回】
実装(3) 【クラウドアプリケーションのためのオブジェクト指向分析設計講座 第32回】
 
実装(2) 【クラウドアプリケーションのためのオブジェクト指向分析設計講座 第31回】
実装(2) 【クラウドアプリケーションのためのオブジェクト指向分析設計講座 第31回】実装(2) 【クラウドアプリケーションのためのオブジェクト指向分析設計講座 第31回】
実装(2) 【クラウドアプリケーションのためのオブジェクト指向分析設計講座 第31回】
 
実装(1) 【クラウドアプリケーションのためのオブジェクト指向分析設計講座 第30回】
実装(1) 【クラウドアプリケーションのためのオブジェクト指向分析設計講座 第30回】実装(1) 【クラウドアプリケーションのためのオブジェクト指向分析設計講座 第30回】
実装(1) 【クラウドアプリケーションのためのオブジェクト指向分析設計講座 第30回】
 
設計/UX/UI 【クラウドアプリケーションのためのオブジェクト指向分析設計講座 第29回】
設計/UX/UI 【クラウドアプリケーションのためのオブジェクト指向分析設計講座 第29回】設計/UX/UI 【クラウドアプリケーションのためのオブジェクト指向分析設計講座 第29回】
設計/UX/UI 【クラウドアプリケーションのためのオブジェクト指向分析設計講座 第29回】
 
設計/原理 【クラウドアプリケーションのためのオブジェクト指向分析設計講座 第28回】
設計/原理 【クラウドアプリケーションのためのオブジェクト指向分析設計講座 第28回】設計/原理 【クラウドアプリケーションのためのオブジェクト指向分析設計講座 第28回】
設計/原理 【クラウドアプリケーションのためのオブジェクト指向分析設計講座 第28回】
 
設計/ドメイン設計(5) 【クラウドアプリケーションのためのオブジェクト指向分析設計講座 第27回】
設計/ドメイン設計(5) 【クラウドアプリケーションのためのオブジェクト指向分析設計講座 第27回】設計/ドメイン設計(5) 【クラウドアプリケーションのためのオブジェクト指向分析設計講座 第27回】
設計/ドメイン設計(5) 【クラウドアプリケーションのためのオブジェクト指向分析設計講座 第27回】
 
設計/ドメイン設計(4) 【クラウドアプリケーションのためのオブジェクト指向分析設計講座 第26回】
設計/ドメイン設計(4) 【クラウドアプリケーションのためのオブジェクト指向分析設計講座 第26回】設計/ドメイン設計(4) 【クラウドアプリケーションのためのオブジェクト指向分析設計講座 第26回】
設計/ドメイン設計(4) 【クラウドアプリケーションのためのオブジェクト指向分析設計講座 第26回】
 
設計/ドメイン設計(3) 【クラウドアプリケーションのためのオブジェクト指向分析設計講座 第25回】
設計/ドメイン設計(3) 【クラウドアプリケーションのためのオブジェクト指向分析設計講座 第25回】設計/ドメイン設計(3) 【クラウドアプリケーションのためのオブジェクト指向分析設計講座 第25回】
設計/ドメイン設計(3) 【クラウドアプリケーションのためのオブジェクト指向分析設計講座 第25回】
 
設計/ドメイン設計(2) 【クラウドアプリケーションのためのオブジェクト指向分析設計講座 第24回】
設計/ドメイン設計(2) 【クラウドアプリケーションのためのオブジェクト指向分析設計講座 第24回】設計/ドメイン設計(2) 【クラウドアプリケーションのためのオブジェクト指向分析設計講座 第24回】
設計/ドメイン設計(2) 【クラウドアプリケーションのためのオブジェクト指向分析設計講座 第24回】
 
設計/ドメイン設計(1) 【クラウドアプリケーションのためのオブジェクト指向分析設計講座 第23回】
設計/ドメイン設計(1) 【クラウドアプリケーションのためのオブジェクト指向分析設計講座 第23回】設計/ドメイン設計(1) 【クラウドアプリケーションのためのオブジェクト指向分析設計講座 第23回】
設計/ドメイン設計(1) 【クラウドアプリケーションのためのオブジェクト指向分析設計講座 第23回】
 
設計/コンポーネント設計(3) 【クラウドアプリケーションのためのオブジェクト指向分析設計講座 第22回】
設計/コンポーネント設計(3) 【クラウドアプリケーションのためのオブジェクト指向分析設計講座 第22回】設計/コンポーネント設計(3) 【クラウドアプリケーションのためのオブジェクト指向分析設計講座 第22回】
設計/コンポーネント設計(3) 【クラウドアプリケーションのためのオブジェクト指向分析設計講座 第22回】
 
設計/コンポーネント設計(2) 【クラウドアプリケーションのためのオブジェクト指向分析設計講座 第21回】
設計/コンポーネント設計(2) 【クラウドアプリケーションのためのオブジェクト指向分析設計講座 第21回】設計/コンポーネント設計(2) 【クラウドアプリケーションのためのオブジェクト指向分析設計講座 第21回】
設計/コンポーネント設計(2) 【クラウドアプリケーションのためのオブジェクト指向分析設計講座 第21回】
 
設計/コンポーネント設計(1) 【クラウドアプリケーションのためのオブジェクト指向分析設計講座 第20回】
設計/コンポーネント設計(1) 【クラウドアプリケーションのためのオブジェクト指向分析設計講座 第20回】設計/コンポーネント設計(1) 【クラウドアプリケーションのためのオブジェクト指向分析設計講座 第20回】
設計/コンポーネント設計(1) 【クラウドアプリケーションのためのオブジェクト指向分析設計講座 第20回】
 
設計/アーキテクチャ設計 【クラウドアプリケーションのためのオブジェクト指向分析設計講座 第19回】
設計/アーキテクチャ設計 【クラウドアプリケーションのためのオブジェクト指向分析設計講座 第19回】設計/アーキテクチャ設計 【クラウドアプリケーションのためのオブジェクト指向分析設計講座 第19回】
設計/アーキテクチャ設計 【クラウドアプリケーションのためのオブジェクト指向分析設計講座 第19回】
 
設計 【クラウドアプリケーションのためのオブジェクト指向分析設計講座 第18回】
設計 【クラウドアプリケーションのためのオブジェクト指向分析設計講座 第18回】設計 【クラウドアプリケーションのためのオブジェクト指向分析設計講座 第18回】
設計 【クラウドアプリケーションのためのオブジェクト指向分析設計講座 第18回】
 
分析/イベント駆動 【クラウドアプリケーションのためのオブジェクト指向分析設計講座 第17回】
分析/イベント駆動 【クラウドアプリケーションのためのオブジェクト指向分析設計講座 第17回】分析/イベント駆動 【クラウドアプリケーションのためのオブジェクト指向分析設計講座 第17回】
分析/イベント駆動 【クラウドアプリケーションのためのオブジェクト指向分析設計講座 第17回】
 
分析/コンポーネント分析 【クラウドアプリケーションのためのオブジェクト指向分析設計講座 第16回】
分析/コンポーネント分析 【クラウドアプリケーションのためのオブジェクト指向分析設計講座 第16回】分析/コンポーネント分析 【クラウドアプリケーションのためのオブジェクト指向分析設計講座 第16回】
分析/コンポーネント分析 【クラウドアプリケーションのためのオブジェクト指向分析設計講座 第16回】
 
分析 【クラウドアプリケーションのためのオブジェクト指向分析設計講座 第15回】
分析 【クラウドアプリケーションのためのオブジェクト指向分析設計講座 第15回】分析 【クラウドアプリケーションのためのオブジェクト指向分析設計講座 第15回】
分析 【クラウドアプリケーションのためのオブジェクト指向分析設計講座 第15回】
 

Recently uploaded

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Recently uploaded (20)

DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Cyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfCyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdf
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
 

楽々Scalaプログラミング

  • 2. •  Object-Oriented Programming (OOP) Object- Functional Programming (OFP) •  •  • 
  • 3. ⾃自⼰己 •  ⽇日 Java ⻑⾧長 ( ) Lab •  •  XML SmartDoc (XML⽂文 ) •  Relaxer (XML/Java ) •  •  SimpleModeler (Scala DSL ) •  g3 ( ) •  g4 (Android ) •  •  ⼯工 UML (⽇日 BP) •  ( ) •  Scala (Softbank Creative)
  • 4.
  • 5. •  Modegramming Style ( DSL ) •  http://modegramming.blogspot.com/ •  SimpleModeler •  http://code.google.com/p/simplemodeler/ •  g3 •  http://code.google.com/p/goldenport3/ •  g4 •  https://github.com/asami/goldenport-android-library
  • 6. SCALA ⾔言
  • 8. Scala ⽤用 • ⾼高 ⽣生 •  3 • DSL (Domain Specific Language) •  •  API •  ⾏行行 •  Many Core •  Parallel Everything
  • 9. ⾔言 •  ⾼高 •  •  •  ( )
  • 10. ⾔言 ⻑⾧長 •  ⻑⾧長 •  ⾼高 •  List, ( ) •  •  ( ) ( ) ( ⼊入 ) •  •  ⾏行行 •  •  ⼤大 •  •  ⼤大 •  ⽤用 • 
  • 11. ⾔言 •  ⾔言 •  ⾔言 •  pure Lisp •  Haskell •  •  Scala(+scalaz) •  ⾔言 •  •  Lisp, ML, OCaml •  •  •  Parametric •  ⼿手 polymorphism •  •  •  •  Subtype polymorphism
  • 12.
  • 13. DSL (Domain Specific Language) •  ⾔言 DSL •  ⾼高 •  Scala DSL ⽅方 •  JJUG CCC 2010 Fall •  http://www.slideshare.net/asami224/scala-dsl
  • 14. val CNN = "http://www.cnn.com"! val YAHOO = "http://www.yahoo.com"! val AMAZON = "http://www.amazon.com"! ! def sitelen(url: String): Int = {! import scala.io.Source! val source = scala.io.Source.fromURL(url)! source.getLines.map(_.length).sum! }! scala> sitelen(CNN)! res92: Int = 85569
  • 15. List(CNN, YAHOO, AMAZON).map(sitelen).sum ⾏行行 6.3 (scala.testing.Benchmark ) List(CNN, YAHOO, AMAZON).par.map(sitelen).sum ⾏行行 2 (scala.testing.Benchmark )
  • 16. Future •  ⾮非 ⾏行行 ⾏行行 •  ⾏行行 ⾏行行 •  ⾏行行 ⾏行行 ⾏行行 •  Java (java.util.concurrent) •  Scala (scala.actors) •  Future ⾏行行
  • 17. import java.util.concurrent._! ! val e = Executors.newSingleThreadExecutor! val f: Future[Int] = e.submit(! new Callable[Int] {! def call() = {! sitelen(CNN)! }! })! ! f.get! import scala.actors.Futures._! ! val length = future { sitelen(CNN) }! length()!
  • 18. Promise •  ⾮非 ⾏行行 ⾏行行 •  ⾏行行 ⾏行行 •  ⾏行行 ⾏行行 ⾏行行 •  Future •  ⾮非 ⾏行行
  • 19. import scalaz._! import Scalaz._! ! // def sitelen(url: String): Int = ...! def sizekind(len: Int) = {! if (len > 10000) "Large" ! else "Small"! }! def sitelenpromise = (sitelen _).promise! def sizekindpromise = (sizekind _).promise! def sitekindpromise = {! sitelenpromise >=> sizekindpromise! }! scala> val p = sitekindpromise(CNN)! res105: scalaz.concurrent.Promise [java.lang.String] = <promise>! scala> p.get! res107: java.lang.String = Large!
  • 20. 5
  • 21. 1: y = f(x) •  •  •  ⼤大
  • 22. def add1(a: Int): Int = a + 1 add1 (Int) => Int scala> add1(3)! res84: Int = 4 scala> List(1, 2, 3).map(add1)! res83: List[Int] = List(2, 3, 4) def add(a: Int, b: Int): Int = a + b addx (Int, Int) => Int scala> List(1, 2, 3).map(add)! <console>:34: error: type mismatch;! found : (Int, Int) => Int! required: (Int) => ?! List(1, 2, 3).map(add)! ^!
  • 23. def addc(a: Int)(b: Int): Int = a + b addc (Int) => (Int) => Int Int (Int) => Int scala> val x = List(1, 2, 3).map(addc)! res87: List[(Int) => Int] = List (<function1>, <function1>, <function1>)! scala> x.map(f => f(1))! res89: List[Int] = List(2, 3, 4)!
  • 24. 2: •  •  •  ⼩小 •  ⾏行行
  • 25. case class ()! case class 1()! case class 2()! case class ( 1: 1, !                    2: 2)! ! def 1 (a: ) = 1()! def 2 (a: ) = 2()! ! def (a: ): = {! ( 1 (a),! 2 (a))! }!
  • 26. def qsort(a: List[Int]): List[Int] = {! a match {! case Nil => Nil! case List(a) => List(a)! case List(a, b) => if (a < b) List(a, b) ! else List(b, a)! case _ => {! val small = a.filter(_ < a.head)! val large = a.filter(_ > a.head)! qsort(small) ::: List(a.head) ::: qsort(large)! }! }! }! scala> qsort(List(10, 3, 8, 5, 2, 6))! res142: List[Int] = List(2, 3, 5, 6, 8, 10)!
  • 27. 3:
  • 28. def zeroonetwo(a: Int): List[Int] = {! List(a, a + 1, a + 2)! } map scala> List(1, 2, 3).map(zeroonetwo)! res138: List[List[Int]] = ! List(List(1, 2, 3), List(2, 3, 4), List(3, 4, 5)) flatMap scala> List(1, 2, 3).flatMap(zeroonetwo)! res139: List[Int] = List(1, 2, 3, 2, 3, 4, 3, 4, 5)
  • 29. foldLeft def partition5(l: List[Int]) = {! l.foldLeft((List[Int](), List[Int]())) { (xs, x) =>! val (lhs, rhs) = xs! if (x > 5) (lhs, x :: rhs) else (x :: lhs, rhs)! }! }! def partition5(l: List[Int]) = {! ((List[Int](), List[Int]()) /: l) { (xs, x) =>! val (lhs, rhs) = xs! if (x > 5) (lhs, x :: rhs) else (x :: lhs, rhs)! }! }! scala> partition5(List(10, 3, 8, 5, 2, 6))! res130: (List[Int], List[Int]) = ! (List(2, 5, 3),List(6, 8, 10))!
  • 30.
  • 31. 4:
  • 32.
  • 33. •  (referential transparency) •  ⾔言 ⼀一 ⽂文 ⾔言 (Wikipedia) •  (persistent data structure) •  ⽣生 ⽤用 (Wikipedia) •  Scala •  Value •  scala.collection.immutable •  case class ⽤用 •  OOP DTO case class
  • 34. case class Person(name: String, email: String)! case class Party(name: String, persons: List[Person])! ! val party = Party(! "hobby",! List(Person("Taro", "taro@example.com"),! Person("Hanako", "hanako@example.com")))!
  • 35. ⽤用 •  ⼿手 •  •  • 
  • 36. 5: •  ⾼高 ⼤大 •  Functor ( ⼿手) •  Subgroup ( ) •  Monoid ( ) •  Monad ( ) •  ⾊色 •  ( ) •  ⾼高 •  •  OOP •  Visitor, AbstractFactory, TemplateMethod, Memento •  ⾊色
  • 37. Functor List(CNN, YAHOO, AMAZON).map(sitelen) List(86076, 166806, 98089)! Monad for (x <- List(1, 2, 3);! y <- List(10, 20, 30)) yield x * y List(10, 20, 30, 20, 40, 60, 30, 60, 90)! Applicative Functor import scalaz._! import Scalaz._! List(10, 20, 30) <*> (List(1, 2, 3) <*>! ((_: Int) * (_: Int)).curried.pure[List]) List(10, 20, 30, 20, 40, 60, 30, 60, 90)!
  • 38. •  1: y = f(x) •  2: •  3: •  4: •  5:
  • 39. END