SlideShare a Scribd company logo
scala
dla programistów ruby :)



   Tymon Tobolski
   http://teamon.eu
Scala - ???

• OOP + FP
• statycznie typowany
• kompilowany do JVM
• intergacja z Java
scala jest trudna
trait FilterMonadic[+A, +Repr] {
  def map[B, That](f: A => B)(implicit bf: CanBuildFrom[Repr, B, That]): That
  // ...
}

def zipWithIndexIf[T](list: List[T])(pred: T => Boolean): List[(T, Option[Int])] = {
    type R = List[(T, Option[Int])]
    def doZip(zipped: R, left: List[T], index: Int): R = left match {
        case x :: xs if pred(x) => doZip((x, Some(index)) :: zipped, xs, index + 1)
        case x :: xs => doZip((x, None) :: zipped, xs, index)
        case Nil => zipped
    }

    doZip(Nil, list, 0).reverse
}
scala jest trudna
trait FilterMonadic[+A, +Repr] {
  def map[B, That](f: A => B)(implicit bf: CanBuildFrom[Repr, B, That]): That
  // ...
}

def zipWithIndexIf[T](list: List[T])(pred: T => Boolean): List[(T, Option[Int])] = {
    type R = List[(T, Option[Int])]
    def doZip(zipped: R, left: List[T], index: Int): R = left match {
        case x :: xs if pred(x) => doZip((x, Some(index)) :: zipped, xs, index + 1)
        case x :: xs => doZip((x, None) :: zipped, xs, index)
        case Nil => zipped
    }

    doZip(Nil, list, 0).reverse
}
serio?
List(1,2,3) map { e => e * 2 } // List[Int] = List(2, 4, 6)
serio?
List(1,2,3) map { e => e * 2 } // List[Int] = List(2, 4, 6)

List(1,2,3) map (_*2) // List[Int] = List(2, 4, 6)

List(1,2,3) map (2*) // List[Int] = List(2, 4, 6)

List(1,2,3) filter { _ > 1 } // List[Int] = List(2, 3)

(1 to 10) foreach { e => println(e) }

(1 to 10) foreach println
Monkey patching


      2.days
Monkey patching
  Implicit
conversions
implicit def Int2Time(i: Int) = new {
  def days = i * 24* 60 * 60
}

2.days // 172800
Modules / Traits
module T1
  def foo
    "foo"
  end
end

module T2
  def bar
    "bar"
  end
end

class A
  include T1
  include T2
end

a = A.new
a.foo # => "foo"
a.bar # => "bar"
Modules / Traits
module T1
  def foo
    "foo"
  end
                   trait T1 {
end
                     def foo = "foo"
                   }
module T2
  def bar
                   trait T2 {
    "bar"
                     def bar = "bar"
  end
                   }
end
                   class A extends T1 with T2
class A
  include T1
                   val a = new A
  include T2
                   a.foo // "foo"
end
                   a.bar // "bar"
a = A.new
a.foo # => "foo"
a.bar # => "bar"
Singleton
class A
  def foo
    "instance"
  end
  
  class << self
    def foo
      "singleton"
    end
  end
end

A.new.foo # => "instance"
A.foo     # => "singleton"
Singleton
class A
  def foo
    "instance"               class A {
  end                          def foo = "instance"
                             }
  class << self
    def foo                  object A {
      "singleton"              def foo "singleton"
    end                      }
  end
end                          new A().foo // "instance"
                             A.foo       // "singleton"
A.new.foo # => "instance"
A.foo     # => "singleton"
Duck typing
class Duck
  def quack
  def walk
end

class Dove
  def quack
  def walk
end

class Cat
end

def quack_and_walk(animal)
  animal.quack
  animal.walk
end

quack_and_walk Duck.new
quack_and_walk Dove.new
quack_and_walk Cat.new # NoMethodError
Duck typing
class Duck                               class Duck {
  def quack                                def quack
  def walk                                 def walk
end                                      }

class Dove                               class Dove {
  def quack                                def quack
  def walk                                 def walk
end                                      }

class Cat                                class Cat
end
                                         def quackAndWalk(a: { def quack; def walk }) = {
def quack_and_walk(animal)                 a.quack
  animal.quack                             a.walk
  animal.walk                            }
end
                                         quackAndWalk(new Duck)
quack_and_walk Duck.new                  quackAndWalk(new Dove)
quack_and_walk Dove.new                  quackAndWalk(new Cat) // Compile error
quack_and_walk Cat.new # NoMethodError
DSL
class StackSpec extends FlatSpec with ShouldMatchers {

  "A Stack" should "pop values in last-in-first-out order" in {
    val stack = new Stack[Int]
    stack.push(1)
    stack.push(2)
    stack.pop() should equal (2)
    stack.pop() should equal (1)
  }

  it should "throw NoSuchElementException if an empty stack is popped" in {
    val emptyStack = new Stack[String]
    evaluating { emptyStack.pop() } should produce [NoSuchElementException]
  }
}




                             http://scalatest.org
DSL
class FilterExample extends ScalatraFilter {
  get("/hello") {
    <p>
      Hello world
    </p>
  }

  post("/world") {
    // ...
  }
}



           https://github.com/scalatra/scalatra
Immutability

val list = List(2, 3)
val list2 = 1 :: list

println(list) // List(2, 3)
println(list2) // List(1, 2, 3)
Built-in concurency
scala> (1 to 10) foreach println
1
2
3
4
5
6
7
8
9
10
Built-in concurency
scala> (1 to 10).par foreach println
1
2
3
4
5
8
9
10
6
7
Functional style
scala> Map(1 -> 2)
res9: scala.collection.immutable.Map[Int,Int] = Map(1 -> 2)
Functional style
scala> Map(1 -> 2)
res9: scala.collection.immutable.Map[Int,Int] = Map(1 -> 2)
scala> Map(1 -> 2) get _
res10: (Int) => Option[Int] = <function1>
Functional style
scala> Map(1 -> 2)
res9: scala.collection.immutable.Map[Int,Int] = Map(1 -> 2)
scala> Map(1 -> 2) get _
res10: (Int) => Option[Int] = <function1>
scala> Map(1 -> 2) get 1
res11: Option[Int] = Some(2)
Functional style
scala> Map(1 -> 2)
res9: scala.collection.immutable.Map[Int,Int] = Map(1 -> 2)
scala> Map(1 -> 2) get _
res10: (Int) => Option[Int] = <function1>
scala> Map(1 -> 2) get 1
res11: Option[Int] = Some(2)
scala> Map(1 -> 2) get 3
res12: Option[Int] = None
Functional style
scala> Map(1 -> 2)
res9: scala.collection.immutable.Map[Int,Int] = Map(1 -> 2)
scala> Map(1 -> 2) get _
res10: (Int) => Option[Int] = <function1>
scala> Map(1 -> 2) get 1
res11: Option[Int] = Some(2)
scala> Map(1 -> 2) get 3
res12: Option[Int] = None
scala> Map(1 -> 2) get 1 map (1+)
res13: Option[Int] = Some(3)
Functional style
scala> Map(1 -> 2)
res9: scala.collection.immutable.Map[Int,Int] = Map(1 -> 2)
scala> Map(1 -> 2) get _
res10: (Int) => Option[Int] = <function1>
scala> Map(1 -> 2) get 1
res11: Option[Int] = Some(2)
scala> Map(1 -> 2) get 3
res12: Option[Int] = None
scala> Map(1 -> 2) get 1 map (1+)
res13: Option[Int] = Some(3)
scala> Map(1 -> 2) get 3 map (1+)
res14: Option[Int] = None
Functional style
scala> Map(1 -> 2)
res9: scala.collection.immutable.Map[Int,Int] = Map(1 -> 2)
scala> Map(1 -> 2) get _
res10: (Int) => Option[Int] = <function1>
scala> Map(1 -> 2) get 1
res11: Option[Int] = Some(2)
scala> Map(1 -> 2) get 3
res12: Option[Int] = None
scala> Map(1 -> 2) get 1 map (1+)
res13: Option[Int] = Some(3)
scala> Map(1 -> 2) get 3 map (1+)
res14: Option[Int] = None
scala> Map(1 -> 2) get 1 map (1+) getOrElse 5
res15: Int = 3
Functional style
scala> Map(1 -> 2)
res9: scala.collection.immutable.Map[Int,Int] = Map(1 -> 2)
scala> Map(1 -> 2) get _
res10: (Int) => Option[Int] = <function1>
scala> Map(1 -> 2) get 1
res11: Option[Int] = Some(2)
scala> Map(1 -> 2) get 3
res12: Option[Int] = None
scala> Map(1 -> 2) get 1 map (1+)
res13: Option[Int] = Some(3)
scala> Map(1 -> 2) get 3 map (1+)
res14: Option[Int] = None
scala> Map(1 -> 2) get 1 map (1+) getOrElse 5
res15: Int = 3
scala> Map(1 -> 2) get 3 map (1+) getOrElse 5
res16: Int = 5
Web

                  • Play!
• Rails
                  • Lift
• Sinatra
                  • Scalatra
• ...
                  • ...
• Actors
• STM
• Fault Tolerance
• ...
• http://scala-lang.org
• http://akka.io
• http://typesafe.com
• http://scala.playframework.org/

• #scala @ irc.freenode.net
• #scala.pl @ irc.freenode.net

More Related Content

What's hot (20)

Scala for Jedi
Scala for JediScala for Jedi
Scala for Jedi
Vladimir Parfinenko
 
Scala for curious
Scala for curiousScala for curious
Scala for curious
Tim (dev-tim) Zadorozhniy
 
Introduction to Scala for Java Developers
Introduction to Scala for Java DevelopersIntroduction to Scala for Java Developers
Introduction to Scala for Java Developers
Michael Galpin
 
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
IndicThreads
 
Scala Back to Basics: Type Classes
Scala Back to Basics: Type ClassesScala Back to Basics: Type Classes
Scala Back to Basics: Type Classes
Tomer Gabel
 
Exploring ZIO Prelude: The game changer for typeclasses in Scala
Exploring ZIO Prelude: The game changer for typeclasses in ScalaExploring ZIO Prelude: The game changer for typeclasses in Scala
Exploring ZIO Prelude: The game changer for typeclasses in Scala
Jorge Vásquez
 
Scala vs Java 8 in a Java 8 World
Scala vs Java 8 in a Java 8 WorldScala vs Java 8 in a Java 8 World
Scala vs Java 8 in a Java 8 World
BTI360
 
Joy of scala
Joy of scalaJoy of scala
Joy of scala
Maxim Novak
 
First-Class Patterns
First-Class PatternsFirst-Class Patterns
First-Class Patterns
John De Goes
 
Type classes 101 - classification beyond inheritance
Type classes 101 - classification beyond inheritanceType classes 101 - classification beyond inheritance
Type classes 101 - classification beyond inheritance
Alexey Raga
 
Scala for Java Developers - Intro
Scala for Java Developers - IntroScala for Java Developers - Intro
Scala for Java Developers - Intro
David Copeland
 
Intro to Functional Programming in Scala
Intro to Functional Programming in ScalaIntro to Functional Programming in Scala
Intro to Functional Programming in Scala
Shai Yallin
 
Exploring type level programming in Scala
Exploring type level programming in ScalaExploring type level programming in Scala
Exploring type level programming in Scala
Jorge Vásquez
 
Monad Transformers In The Wild
Monad Transformers In The WildMonad Transformers In The Wild
Monad Transformers In The Wild
StackMob Inc
 
Scala presentation by Aleksandar Prokopec
Scala presentation by Aleksandar ProkopecScala presentation by Aleksandar Prokopec
Scala presentation by Aleksandar Prokopec
Loïc Descotte
 
Pragmatic Real-World Scala (short version)
Pragmatic Real-World Scala (short version)Pragmatic Real-World Scala (short version)
Pragmatic Real-World Scala (short version)
Jonas Bonér
 
Scala Intro
Scala IntroScala Intro
Scala Intro
Paolo Platter
 
Quark: A Purely-Functional Scala DSL for Data Processing & Analytics
Quark: A Purely-Functional Scala DSL for Data Processing & AnalyticsQuark: A Purely-Functional Scala DSL for Data Processing & Analytics
Quark: A Purely-Functional Scala DSL for Data Processing & Analytics
John De Goes
 
The Death of Final Tagless
The Death of Final TaglessThe Death of Final Tagless
The Death of Final Tagless
John De Goes
 
The Ring programming language version 1.4.1 book - Part 9 of 31
The Ring programming language version 1.4.1 book - Part 9 of 31The Ring programming language version 1.4.1 book - Part 9 of 31
The Ring programming language version 1.4.1 book - Part 9 of 31
Mahmoud Samir Fayed
 
Introduction to Scala for Java Developers
Introduction to Scala for Java DevelopersIntroduction to Scala for Java Developers
Introduction to Scala for Java Developers
Michael Galpin
 
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
IndicThreads
 
Scala Back to Basics: Type Classes
Scala Back to Basics: Type ClassesScala Back to Basics: Type Classes
Scala Back to Basics: Type Classes
Tomer Gabel
 
Exploring ZIO Prelude: The game changer for typeclasses in Scala
Exploring ZIO Prelude: The game changer for typeclasses in ScalaExploring ZIO Prelude: The game changer for typeclasses in Scala
Exploring ZIO Prelude: The game changer for typeclasses in Scala
Jorge Vásquez
 
Scala vs Java 8 in a Java 8 World
Scala vs Java 8 in a Java 8 WorldScala vs Java 8 in a Java 8 World
Scala vs Java 8 in a Java 8 World
BTI360
 
First-Class Patterns
First-Class PatternsFirst-Class Patterns
First-Class Patterns
John De Goes
 
Type classes 101 - classification beyond inheritance
Type classes 101 - classification beyond inheritanceType classes 101 - classification beyond inheritance
Type classes 101 - classification beyond inheritance
Alexey Raga
 
Scala for Java Developers - Intro
Scala for Java Developers - IntroScala for Java Developers - Intro
Scala for Java Developers - Intro
David Copeland
 
Intro to Functional Programming in Scala
Intro to Functional Programming in ScalaIntro to Functional Programming in Scala
Intro to Functional Programming in Scala
Shai Yallin
 
Exploring type level programming in Scala
Exploring type level programming in ScalaExploring type level programming in Scala
Exploring type level programming in Scala
Jorge Vásquez
 
Monad Transformers In The Wild
Monad Transformers In The WildMonad Transformers In The Wild
Monad Transformers In The Wild
StackMob Inc
 
Scala presentation by Aleksandar Prokopec
Scala presentation by Aleksandar ProkopecScala presentation by Aleksandar Prokopec
Scala presentation by Aleksandar Prokopec
Loïc Descotte
 
Pragmatic Real-World Scala (short version)
Pragmatic Real-World Scala (short version)Pragmatic Real-World Scala (short version)
Pragmatic Real-World Scala (short version)
Jonas Bonér
 
Quark: A Purely-Functional Scala DSL for Data Processing & Analytics
Quark: A Purely-Functional Scala DSL for Data Processing & AnalyticsQuark: A Purely-Functional Scala DSL for Data Processing & Analytics
Quark: A Purely-Functional Scala DSL for Data Processing & Analytics
John De Goes
 
The Death of Final Tagless
The Death of Final TaglessThe Death of Final Tagless
The Death of Final Tagless
John De Goes
 
The Ring programming language version 1.4.1 book - Part 9 of 31
The Ring programming language version 1.4.1 book - Part 9 of 31The Ring programming language version 1.4.1 book - Part 9 of 31
The Ring programming language version 1.4.1 book - Part 9 of 31
Mahmoud Samir Fayed
 

Similar to Scala for ruby programmers (20)

Demystifying functional programming with Scala
Demystifying functional programming with ScalaDemystifying functional programming with Scala
Demystifying functional programming with Scala
Denis
 
(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を使う
ハイブリッド言語Scalaを使うハイブリッド言語Scalaを使う
ハイブリッド言語Scalaを使う
bpstudy
 
Monadologie
MonadologieMonadologie
Monadologie
league
 
Scala - where objects and functions meet
Scala - where objects and functions meetScala - where objects and functions meet
Scala - where objects and functions meet
Mario Fusco
 
学生向けScalaハンズオンテキスト
学生向けScalaハンズオンテキスト学生向けScalaハンズオンテキスト
学生向けScalaハンズオンテキスト
Opt Technologies
 
An introduction to scala
An introduction to scalaAn introduction to scala
An introduction to scala
Mohsen Zainalpour
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to Scala
Aleksandar Prokopec
 
Scala Functional Patterns
Scala Functional PatternsScala Functional Patterns
Scala Functional Patterns
league
 
Kotlin Advanced - Apalon Kotlin Sprint Part 3
Kotlin Advanced - Apalon Kotlin Sprint Part 3Kotlin Advanced - Apalon Kotlin Sprint Part 3
Kotlin Advanced - Apalon Kotlin Sprint Part 3
Kirill Rozov
 
Scala introduction
Scala introductionScala introduction
Scala introduction
vito jeng
 
Scala Paradigms
Scala ParadigmsScala Paradigms
Scala Paradigms
Tom Flaherty
 
Scala
ScalaScala
Scala
Sven Efftinge
 
A Brief Intro to Scala
A Brief Intro to ScalaA Brief Intro to Scala
A Brief Intro to Scala
Tim Underwood
 
GeoGebra JavaScript CheatSheet
GeoGebra JavaScript CheatSheetGeoGebra JavaScript CheatSheet
GeoGebra JavaScript CheatSheet
Jose Perez
 
Meet scala
Meet scalaMeet scala
Meet scala
Wojciech Pituła
 
Scala @ TechMeetup Edinburgh
Scala @ TechMeetup EdinburghScala @ TechMeetup Edinburgh
Scala @ TechMeetup Edinburgh
Stuart Roebuck
 
Are we ready to Go?
Are we ready to Go?Are we ready to Go?
Are we ready to Go?
Adam Dudczak
 
Graphic programming using Turtle class in Python
Graphic programming using Turtle class in PythonGraphic programming using Turtle class in Python
Graphic programming using Turtle class in Python
KanadamKarteekaPavan1
 
Hw09 Hadoop + Clojure
Hw09   Hadoop + ClojureHw09   Hadoop + Clojure
Hw09 Hadoop + Clojure
Cloudera, Inc.
 
Demystifying functional programming with Scala
Demystifying functional programming with ScalaDemystifying functional programming with Scala
Demystifying functional programming with Scala
Denis
 
(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を使う
ハイブリッド言語Scalaを使うハイブリッド言語Scalaを使う
ハイブリッド言語Scalaを使う
bpstudy
 
Monadologie
MonadologieMonadologie
Monadologie
league
 
Scala - where objects and functions meet
Scala - where objects and functions meetScala - where objects and functions meet
Scala - where objects and functions meet
Mario Fusco
 
学生向けScalaハンズオンテキスト
学生向けScalaハンズオンテキスト学生向けScalaハンズオンテキスト
学生向けScalaハンズオンテキスト
Opt Technologies
 
Scala Functional Patterns
Scala Functional PatternsScala Functional Patterns
Scala Functional Patterns
league
 
Kotlin Advanced - Apalon Kotlin Sprint Part 3
Kotlin Advanced - Apalon Kotlin Sprint Part 3Kotlin Advanced - Apalon Kotlin Sprint Part 3
Kotlin Advanced - Apalon Kotlin Sprint Part 3
Kirill Rozov
 
Scala introduction
Scala introductionScala introduction
Scala introduction
vito jeng
 
A Brief Intro to Scala
A Brief Intro to ScalaA Brief Intro to Scala
A Brief Intro to Scala
Tim Underwood
 
GeoGebra JavaScript CheatSheet
GeoGebra JavaScript CheatSheetGeoGebra JavaScript CheatSheet
GeoGebra JavaScript CheatSheet
Jose Perez
 
Scala @ TechMeetup Edinburgh
Scala @ TechMeetup EdinburghScala @ TechMeetup Edinburgh
Scala @ TechMeetup Edinburgh
Stuart Roebuck
 
Are we ready to Go?
Are we ready to Go?Are we ready to Go?
Are we ready to Go?
Adam Dudczak
 
Graphic programming using Turtle class in Python
Graphic programming using Turtle class in PythonGraphic programming using Turtle class in Python
Graphic programming using Turtle class in Python
KanadamKarteekaPavan1
 
Ad

Recently uploaded (20)

Dancing with AI - A Developer's Journey.pptx
Dancing with AI - A Developer's Journey.pptxDancing with AI - A Developer's Journey.pptx
Dancing with AI - A Developer's Journey.pptx
Elliott Richmond
 
TimeSeries Machine Learning - PyData London 2025
TimeSeries Machine Learning - PyData London 2025TimeSeries Machine Learning - PyData London 2025
TimeSeries Machine Learning - PyData London 2025
Suyash Joshi
 
ELNL2025 - Unlocking the Power of Sensitivity Labels - A Comprehensive Guide....
ELNL2025 - Unlocking the Power of Sensitivity Labels - A Comprehensive Guide....ELNL2025 - Unlocking the Power of Sensitivity Labels - A Comprehensive Guide....
ELNL2025 - Unlocking the Power of Sensitivity Labels - A Comprehensive Guide....
Jasper Oosterveld
 
6th Power Grid Model Meetup - 21 May 2025
6th Power Grid Model Meetup - 21 May 20256th Power Grid Model Meetup - 21 May 2025
6th Power Grid Model Meetup - 21 May 2025
DanBrown980551
 
FME Beyond Data Processing Creating A Dartboard Accuracy App
FME Beyond Data Processing Creating A Dartboard Accuracy AppFME Beyond Data Processing Creating A Dartboard Accuracy App
FME Beyond Data Processing Creating A Dartboard Accuracy App
Safe Software
 
Improving Developer Productivity With DORA, SPACE, and DevEx
Improving Developer Productivity With DORA, SPACE, and DevExImproving Developer Productivity With DORA, SPACE, and DevEx
Improving Developer Productivity With DORA, SPACE, and DevEx
Justin Reock
 
What is Oracle EPM A Guide to Oracle EPM Cloud Everything You Need to Know
What is Oracle EPM A Guide to Oracle EPM Cloud Everything You Need to KnowWhat is Oracle EPM A Guide to Oracle EPM Cloud Everything You Need to Know
What is Oracle EPM A Guide to Oracle EPM Cloud Everything You Need to Know
SMACT Works
 
If You Use Databricks, You Definitely Need FME
If You Use Databricks, You Definitely Need FMEIf You Use Databricks, You Definitely Need FME
If You Use Databricks, You Definitely Need FME
Safe Software
 
ISOIEC 42005 Revolutionalises AI Impact Assessment.pptx
ISOIEC 42005 Revolutionalises AI Impact Assessment.pptxISOIEC 42005 Revolutionalises AI Impact Assessment.pptx
ISOIEC 42005 Revolutionalises AI Impact Assessment.pptx
AyilurRamnath1
 
Data Virtualization: Bringing the Power of FME to Any Application
Data Virtualization: Bringing the Power of FME to Any ApplicationData Virtualization: Bringing the Power of FME to Any Application
Data Virtualization: Bringing the Power of FME to Any Application
Safe Software
 
Integration of Utility Data into 3D BIM Models Using a 3D Solids Modeling Wor...
Integration of Utility Data into 3D BIM Models Using a 3D Solids Modeling Wor...Integration of Utility Data into 3D BIM Models Using a 3D Solids Modeling Wor...
Integration of Utility Data into 3D BIM Models Using a 3D Solids Modeling Wor...
Safe Software
 
vertical-cnc-processing-centers-drillteq-v-200-en.pdf
vertical-cnc-processing-centers-drillteq-v-200-en.pdfvertical-cnc-processing-centers-drillteq-v-200-en.pdf
vertical-cnc-processing-centers-drillteq-v-200-en.pdf
AmirStern2
 
Trends Artificial Intelligence - Mary Meeker
Trends Artificial Intelligence - Mary MeekerTrends Artificial Intelligence - Mary Meeker
Trends Artificial Intelligence - Mary Meeker
Clive Dickens
 
Introduction to Typescript - GDG On Campus EUE
Introduction to Typescript - GDG On Campus EUEIntroduction to Typescript - GDG On Campus EUE
Introduction to Typescript - GDG On Campus EUE
Google Developer Group On Campus European Universities in Egypt
 
End-to-end Assurance for SD-WAN & SASE with ThousandEyes
End-to-end Assurance for SD-WAN & SASE with ThousandEyesEnd-to-end Assurance for SD-WAN & SASE with ThousandEyes
End-to-end Assurance for SD-WAN & SASE with ThousandEyes
ThousandEyes
 
TrustArc Webinar - 2025 Global Privacy Survey
TrustArc Webinar - 2025 Global Privacy SurveyTrustArc Webinar - 2025 Global Privacy Survey
TrustArc Webinar - 2025 Global Privacy Survey
TrustArc
 
Your startup on AWS - How to architect and maintain a Lean and Mean account J...
Your startup on AWS - How to architect and maintain a Lean and Mean account J...Your startup on AWS - How to architect and maintain a Lean and Mean account J...
Your startup on AWS - How to architect and maintain a Lean and Mean account J...
angelo60207
 
cnc-drilling-dowel-inserting-machine-drillteq-d-510-english.pdf
cnc-drilling-dowel-inserting-machine-drillteq-d-510-english.pdfcnc-drilling-dowel-inserting-machine-drillteq-d-510-english.pdf
cnc-drilling-dowel-inserting-machine-drillteq-d-510-english.pdf
AmirStern2
 
Oracle Cloud Infrastructure Generative AI Professional
Oracle Cloud Infrastructure Generative AI ProfessionalOracle Cloud Infrastructure Generative AI Professional
Oracle Cloud Infrastructure Generative AI Professional
VICTOR MAESTRE RAMIREZ
 
How Advanced Environmental Detection Is Revolutionizing Oil & Gas Safety.pdf
How Advanced Environmental Detection Is Revolutionizing Oil & Gas Safety.pdfHow Advanced Environmental Detection Is Revolutionizing Oil & Gas Safety.pdf
How Advanced Environmental Detection Is Revolutionizing Oil & Gas Safety.pdf
Rejig Digital
 
Dancing with AI - A Developer's Journey.pptx
Dancing with AI - A Developer's Journey.pptxDancing with AI - A Developer's Journey.pptx
Dancing with AI - A Developer's Journey.pptx
Elliott Richmond
 
TimeSeries Machine Learning - PyData London 2025
TimeSeries Machine Learning - PyData London 2025TimeSeries Machine Learning - PyData London 2025
TimeSeries Machine Learning - PyData London 2025
Suyash Joshi
 
ELNL2025 - Unlocking the Power of Sensitivity Labels - A Comprehensive Guide....
ELNL2025 - Unlocking the Power of Sensitivity Labels - A Comprehensive Guide....ELNL2025 - Unlocking the Power of Sensitivity Labels - A Comprehensive Guide....
ELNL2025 - Unlocking the Power of Sensitivity Labels - A Comprehensive Guide....
Jasper Oosterveld
 
6th Power Grid Model Meetup - 21 May 2025
6th Power Grid Model Meetup - 21 May 20256th Power Grid Model Meetup - 21 May 2025
6th Power Grid Model Meetup - 21 May 2025
DanBrown980551
 
FME Beyond Data Processing Creating A Dartboard Accuracy App
FME Beyond Data Processing Creating A Dartboard Accuracy AppFME Beyond Data Processing Creating A Dartboard Accuracy App
FME Beyond Data Processing Creating A Dartboard Accuracy App
Safe Software
 
Improving Developer Productivity With DORA, SPACE, and DevEx
Improving Developer Productivity With DORA, SPACE, and DevExImproving Developer Productivity With DORA, SPACE, and DevEx
Improving Developer Productivity With DORA, SPACE, and DevEx
Justin Reock
 
What is Oracle EPM A Guide to Oracle EPM Cloud Everything You Need to Know
What is Oracle EPM A Guide to Oracle EPM Cloud Everything You Need to KnowWhat is Oracle EPM A Guide to Oracle EPM Cloud Everything You Need to Know
What is Oracle EPM A Guide to Oracle EPM Cloud Everything You Need to Know
SMACT Works
 
If You Use Databricks, You Definitely Need FME
If You Use Databricks, You Definitely Need FMEIf You Use Databricks, You Definitely Need FME
If You Use Databricks, You Definitely Need FME
Safe Software
 
ISOIEC 42005 Revolutionalises AI Impact Assessment.pptx
ISOIEC 42005 Revolutionalises AI Impact Assessment.pptxISOIEC 42005 Revolutionalises AI Impact Assessment.pptx
ISOIEC 42005 Revolutionalises AI Impact Assessment.pptx
AyilurRamnath1
 
Data Virtualization: Bringing the Power of FME to Any Application
Data Virtualization: Bringing the Power of FME to Any ApplicationData Virtualization: Bringing the Power of FME to Any Application
Data Virtualization: Bringing the Power of FME to Any Application
Safe Software
 
Integration of Utility Data into 3D BIM Models Using a 3D Solids Modeling Wor...
Integration of Utility Data into 3D BIM Models Using a 3D Solids Modeling Wor...Integration of Utility Data into 3D BIM Models Using a 3D Solids Modeling Wor...
Integration of Utility Data into 3D BIM Models Using a 3D Solids Modeling Wor...
Safe Software
 
vertical-cnc-processing-centers-drillteq-v-200-en.pdf
vertical-cnc-processing-centers-drillteq-v-200-en.pdfvertical-cnc-processing-centers-drillteq-v-200-en.pdf
vertical-cnc-processing-centers-drillteq-v-200-en.pdf
AmirStern2
 
Trends Artificial Intelligence - Mary Meeker
Trends Artificial Intelligence - Mary MeekerTrends Artificial Intelligence - Mary Meeker
Trends Artificial Intelligence - Mary Meeker
Clive Dickens
 
End-to-end Assurance for SD-WAN & SASE with ThousandEyes
End-to-end Assurance for SD-WAN & SASE with ThousandEyesEnd-to-end Assurance for SD-WAN & SASE with ThousandEyes
End-to-end Assurance for SD-WAN & SASE with ThousandEyes
ThousandEyes
 
TrustArc Webinar - 2025 Global Privacy Survey
TrustArc Webinar - 2025 Global Privacy SurveyTrustArc Webinar - 2025 Global Privacy Survey
TrustArc Webinar - 2025 Global Privacy Survey
TrustArc
 
Your startup on AWS - How to architect and maintain a Lean and Mean account J...
Your startup on AWS - How to architect and maintain a Lean and Mean account J...Your startup on AWS - How to architect and maintain a Lean and Mean account J...
Your startup on AWS - How to architect and maintain a Lean and Mean account J...
angelo60207
 
cnc-drilling-dowel-inserting-machine-drillteq-d-510-english.pdf
cnc-drilling-dowel-inserting-machine-drillteq-d-510-english.pdfcnc-drilling-dowel-inserting-machine-drillteq-d-510-english.pdf
cnc-drilling-dowel-inserting-machine-drillteq-d-510-english.pdf
AmirStern2
 
Oracle Cloud Infrastructure Generative AI Professional
Oracle Cloud Infrastructure Generative AI ProfessionalOracle Cloud Infrastructure Generative AI Professional
Oracle Cloud Infrastructure Generative AI Professional
VICTOR MAESTRE RAMIREZ
 
How Advanced Environmental Detection Is Revolutionizing Oil & Gas Safety.pdf
How Advanced Environmental Detection Is Revolutionizing Oil & Gas Safety.pdfHow Advanced Environmental Detection Is Revolutionizing Oil & Gas Safety.pdf
How Advanced Environmental Detection Is Revolutionizing Oil & Gas Safety.pdf
Rejig Digital
 
Ad

Scala for ruby programmers

  • 1. scala dla programistów ruby :) Tymon Tobolski http://teamon.eu
  • 2. Scala - ??? • OOP + FP • statycznie typowany • kompilowany do JVM • intergacja z Java
  • 3. scala jest trudna trait FilterMonadic[+A, +Repr] {   def map[B, That](f: A => B)(implicit bf: CanBuildFrom[Repr, B, That]): That   // ... } def zipWithIndexIf[T](list: List[T])(pred: T => Boolean): List[(T, Option[Int])] = {     type R = List[(T, Option[Int])]     def doZip(zipped: R, left: List[T], index: Int): R = left match {         case x :: xs if pred(x) => doZip((x, Some(index)) :: zipped, xs, index + 1)         case x :: xs => doZip((x, None) :: zipped, xs, index)         case Nil => zipped     }     doZip(Nil, list, 0).reverse }
  • 4. scala jest trudna trait FilterMonadic[+A, +Repr] {   def map[B, That](f: A => B)(implicit bf: CanBuildFrom[Repr, B, That]): That   // ... } def zipWithIndexIf[T](list: List[T])(pred: T => Boolean): List[(T, Option[Int])] = {     type R = List[(T, Option[Int])]     def doZip(zipped: R, left: List[T], index: Int): R = left match {         case x :: xs if pred(x) => doZip((x, Some(index)) :: zipped, xs, index + 1)         case x :: xs => doZip((x, None) :: zipped, xs, index)         case Nil => zipped     }     doZip(Nil, list, 0).reverse }
  • 5. serio? List(1,2,3) map { e => e * 2 } // List[Int] = List(2, 4, 6)
  • 6. serio? List(1,2,3) map { e => e * 2 } // List[Int] = List(2, 4, 6) List(1,2,3) map (_*2) // List[Int] = List(2, 4, 6) List(1,2,3) map (2*) // List[Int] = List(2, 4, 6) List(1,2,3) filter { _ > 1 } // List[Int] = List(2, 3) (1 to 10) foreach { e => println(e) } (1 to 10) foreach println
  • 8. Monkey patching Implicit conversions implicit def Int2Time(i: Int) = new { def days = i * 24* 60 * 60 } 2.days // 172800
  • 9. Modules / Traits module T1   def foo     "foo"   end end module T2   def bar     "bar"   end end class A   include T1   include T2 end a = A.new a.foo # => "foo" a.bar # => "bar"
  • 10. Modules / Traits module T1   def foo     "foo"   end trait T1 { end   def foo = "foo" } module T2   def bar trait T2 {     "bar"   def bar = "bar"   end } end class A extends T1 with T2 class A   include T1 val a = new A   include T2 a.foo // "foo" end a.bar // "bar" a = A.new a.foo # => "foo" a.bar # => "bar"
  • 11. Singleton class A   def foo     "instance"   end      class << self     def foo       "singleton"     end   end end A.new.foo # => "instance" A.foo # => "singleton"
  • 12. Singleton class A   def foo     "instance" class A {   end   def foo = "instance"    }   class << self     def foo object A {       "singleton"   def foo "singleton"     end }   end end new A().foo // "instance" A.foo // "singleton" A.new.foo # => "instance" A.foo # => "singleton"
  • 13. Duck typing class Duck   def quack   def walk end class Dove   def quack   def walk end class Cat end def quack_and_walk(animal)   animal.quack   animal.walk end quack_and_walk Duck.new quack_and_walk Dove.new quack_and_walk Cat.new # NoMethodError
  • 14. Duck typing class Duck class Duck {   def quack   def quack   def walk   def walk end } class Dove class Dove {   def quack   def quack   def walk   def walk end } class Cat class Cat end def quackAndWalk(a: { def quack; def walk }) = { def quack_and_walk(animal)   a.quack   animal.quack   a.walk   animal.walk } end quackAndWalk(new Duck) quack_and_walk Duck.new quackAndWalk(new Dove) quack_and_walk Dove.new quackAndWalk(new Cat) // Compile error quack_and_walk Cat.new # NoMethodError
  • 15. DSL class StackSpec extends FlatSpec with ShouldMatchers {   "A Stack" should "pop values in last-in-first-out order" in {     val stack = new Stack[Int]     stack.push(1)     stack.push(2)     stack.pop() should equal (2)     stack.pop() should equal (1)   }   it should "throw NoSuchElementException if an empty stack is popped" in {     val emptyStack = new Stack[String]     evaluating { emptyStack.pop() } should produce [NoSuchElementException]   } } http://scalatest.org
  • 16. DSL class FilterExample extends ScalatraFilter {   get("/hello") {     <p>       Hello world     </p>   }   post("/world") { // ...   } } https://github.com/scalatra/scalatra
  • 17. Immutability val list = List(2, 3) val list2 = 1 :: list println(list) // List(2, 3) println(list2) // List(1, 2, 3)
  • 18. Built-in concurency scala> (1 to 10) foreach println 1 2 3 4 5 6 7 8 9 10
  • 19. Built-in concurency scala> (1 to 10).par foreach println 1 2 3 4 5 8 9 10 6 7
  • 20. Functional style scala> Map(1 -> 2) res9: scala.collection.immutable.Map[Int,Int] = Map(1 -> 2)
  • 21. Functional style scala> Map(1 -> 2) res9: scala.collection.immutable.Map[Int,Int] = Map(1 -> 2) scala> Map(1 -> 2) get _ res10: (Int) => Option[Int] = <function1>
  • 22. Functional style scala> Map(1 -> 2) res9: scala.collection.immutable.Map[Int,Int] = Map(1 -> 2) scala> Map(1 -> 2) get _ res10: (Int) => Option[Int] = <function1> scala> Map(1 -> 2) get 1 res11: Option[Int] = Some(2)
  • 23. Functional style scala> Map(1 -> 2) res9: scala.collection.immutable.Map[Int,Int] = Map(1 -> 2) scala> Map(1 -> 2) get _ res10: (Int) => Option[Int] = <function1> scala> Map(1 -> 2) get 1 res11: Option[Int] = Some(2) scala> Map(1 -> 2) get 3 res12: Option[Int] = None
  • 24. Functional style scala> Map(1 -> 2) res9: scala.collection.immutable.Map[Int,Int] = Map(1 -> 2) scala> Map(1 -> 2) get _ res10: (Int) => Option[Int] = <function1> scala> Map(1 -> 2) get 1 res11: Option[Int] = Some(2) scala> Map(1 -> 2) get 3 res12: Option[Int] = None scala> Map(1 -> 2) get 1 map (1+) res13: Option[Int] = Some(3)
  • 25. Functional style scala> Map(1 -> 2) res9: scala.collection.immutable.Map[Int,Int] = Map(1 -> 2) scala> Map(1 -> 2) get _ res10: (Int) => Option[Int] = <function1> scala> Map(1 -> 2) get 1 res11: Option[Int] = Some(2) scala> Map(1 -> 2) get 3 res12: Option[Int] = None scala> Map(1 -> 2) get 1 map (1+) res13: Option[Int] = Some(3) scala> Map(1 -> 2) get 3 map (1+) res14: Option[Int] = None
  • 26. Functional style scala> Map(1 -> 2) res9: scala.collection.immutable.Map[Int,Int] = Map(1 -> 2) scala> Map(1 -> 2) get _ res10: (Int) => Option[Int] = <function1> scala> Map(1 -> 2) get 1 res11: Option[Int] = Some(2) scala> Map(1 -> 2) get 3 res12: Option[Int] = None scala> Map(1 -> 2) get 1 map (1+) res13: Option[Int] = Some(3) scala> Map(1 -> 2) get 3 map (1+) res14: Option[Int] = None scala> Map(1 -> 2) get 1 map (1+) getOrElse 5 res15: Int = 3
  • 27. Functional style scala> Map(1 -> 2) res9: scala.collection.immutable.Map[Int,Int] = Map(1 -> 2) scala> Map(1 -> 2) get _ res10: (Int) => Option[Int] = <function1> scala> Map(1 -> 2) get 1 res11: Option[Int] = Some(2) scala> Map(1 -> 2) get 3 res12: Option[Int] = None scala> Map(1 -> 2) get 1 map (1+) res13: Option[Int] = Some(3) scala> Map(1 -> 2) get 3 map (1+) res14: Option[Int] = None scala> Map(1 -> 2) get 1 map (1+) getOrElse 5 res15: Int = 3 scala> Map(1 -> 2) get 3 map (1+) getOrElse 5 res16: Int = 5
  • 28. Web • Play! • Rails • Lift • Sinatra • Scalatra • ... • ...
  • 29. • Actors • STM • Fault Tolerance • ...
  • 30. • http://scala-lang.org • http://akka.io • http://typesafe.com • http://scala.playframework.org/ • #scala @ irc.freenode.net • #scala.pl @ irc.freenode.net

Editor's Notes