SlideShare a Scribd company logo
1 of 12
Marcelo Cure
WTF is Scala? 
 Multi-paradigm programming lang 
 Created on 2003 by Martin Odersky 
 Based on Java 
 Compiled into Java Byte Code 
 Runs under JVM 
 Integration with Java
Functional Paradigm 
 Executed evaluating expressions 
 Avoids using mutable state 
 Functions treated as values(can be 
passed as functions) 
 No side effects 
 Expressiveness 
 Less Bugs 
 Simpler 
 Less code
Difference example
List manipulation 
scala> val list = (1 to 12).toList 
list: List[Int] = List(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12) 
scala> list.filter(_ % 2 == 0) 
res1: List[Int] = List(2, 4, 6, 8, 10, 12) 
scala> val list = (1 to 12).toList 
list: List[Int] = List(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12) 
scala> val list2 = list.map(_ * 2) 
list2: List[Int] = List(2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24) 
scala> list2.reduceLeft(_ + _) 
res2: Int = 156
FlatMaps 
scala> val fruits = Seq("apple", "banana", "orange") 
fruits: Seq[String] = List(apple, banana, orange) 
scala> fruits.flatMap(_.toUpperCase) 
res13: Seq[Char] = List(A, P, P, L, E, B, A, N, A, N, A, O, R, A, N, G, E)
Anonymous Functions 
scala> var sum = (x:Int,y:Int) => x + y 
sum: (Int, Int) => Int = <function2> 
scala> sum(1,2) 
res3: Int = 3
Pattern Matching 
scala> def toYesOrNo(choice: Int): String = choice match { 
| case 1 => "yes" 
| case 0 => "no" 
| case _ => "error" 
| } 
toYesOrNo: (choice: Int)String 
scala> println(toYesOrNo(1)) 
yes 
scala> println(toYesOrNo(0)) 
no 
scala> println(toYesOrNo(3)) 
error
Case Class 
 Plain and immutable data-holding 
objects 
 Depends exclusively on its constructor 
arguments. 
scala> case class Node(left: Int, right: Int) 
defined class Node 
scala> var node1 = Node(1,2) 
node1: Node = Node(1,2)
High Order Functions 
 Takes other functions as parameter 
 Return functions 
scala> def apply(f: Int => String, v: Int) = f(v) 
apply: (f: Int => String, v: Int)String 
scala> def layout[A](x: A) = "[" + x.toString() + "]" 
layout: [A](x: A)String 
scala> println( apply( layout, 10) ) 
[10]
Web Frameworks 
 Lift Framework 
 Play framework 
 Bowler framework
End

More Related Content

What's hot

Java Collections
Java CollectionsJava Collections
Java Collections
parag
 
Collections In Java
Collections In JavaCollections In Java
Collections In Java
Binoj T E
 

What's hot (20)

JAVA Collections frame work ppt
 JAVA Collections frame work ppt JAVA Collections frame work ppt
JAVA Collections frame work ppt
 
Java Collections
Java CollectionsJava Collections
Java Collections
 
Java collection
Java collectionJava collection
Java collection
 
Arrays
ArraysArrays
Arrays
 
Java - Collections framework
Java - Collections frameworkJava - Collections framework
Java - Collections framework
 
Collection Framework in java
Collection Framework in javaCollection Framework in java
Collection Framework in java
 
L11 array list
L11 array listL11 array list
L11 array list
 
arrays
arraysarrays
arrays
 
5 collection framework
5 collection framework5 collection framework
5 collection framework
 
Java Collection framework
Java Collection frameworkJava Collection framework
Java Collection framework
 
Java Collections Tutorials
Java Collections TutorialsJava Collections Tutorials
Java Collections Tutorials
 
Java Collections | Collections Framework in Java | Java Tutorial For Beginner...
Java Collections | Collections Framework in Java | Java Tutorial For Beginner...Java Collections | Collections Framework in Java | Java Tutorial For Beginner...
Java Collections | Collections Framework in Java | Java Tutorial For Beginner...
 
Csharp_List
Csharp_ListCsharp_List
Csharp_List
 
Python List Comprehensions
Python List ComprehensionsPython List Comprehensions
Python List Comprehensions
 
Collections in Java Notes
Collections in Java NotesCollections in Java Notes
Collections in Java Notes
 
One dimensional 2
One dimensional 2One dimensional 2
One dimensional 2
 
Java Collections Framework
Java Collections FrameworkJava Collections Framework
Java Collections Framework
 
Java ArrayList Tutorial | Edureka
Java ArrayList Tutorial | EdurekaJava ArrayList Tutorial | Edureka
Java ArrayList Tutorial | Edureka
 
Collections in Java
Collections in JavaCollections in Java
Collections in Java
 
Collections In Java
Collections In JavaCollections In Java
Collections In Java
 

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
 
Underscore.js
Underscore.jsUnderscore.js
Underscore.js
timourian
 
Scala presentation by Aleksandar Prokopec
Scala presentation by Aleksandar ProkopecScala presentation by Aleksandar Prokopec
Scala presentation by Aleksandar Prokopec
Loïc Descotte
 

Similar to Scala (20)

Meet scala
Meet scalaMeet scala
Meet scala
 
Scala Collections
Scala CollectionsScala Collections
Scala Collections
 
Scala collections
Scala collectionsScala collections
Scala collections
 
(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?
 
Collections In Scala
Collections In ScalaCollections In Scala
Collections In Scala
 
JBUG 11 - Scala For Java Programmers
JBUG 11 - Scala For Java ProgrammersJBUG 11 - Scala For Java Programmers
JBUG 11 - Scala For Java Programmers
 
R교육1
R교육1R교육1
R교육1
 
Underscore.js
Underscore.jsUnderscore.js
Underscore.js
 
Scala presentation by Aleksandar Prokopec
Scala presentation by Aleksandar ProkopecScala presentation by Aleksandar Prokopec
Scala presentation by Aleksandar Prokopec
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to Scala
 
Introducing scala
Introducing scalaIntroducing scala
Introducing scala
 
Scala Bootcamp 1
Scala Bootcamp 1Scala Bootcamp 1
Scala Bootcamp 1
 
Spark workshop
Spark workshopSpark workshop
Spark workshop
 
Scala 101
Scala 101Scala 101
Scala 101
 
Tuples All the Way Down
Tuples All the Way DownTuples All the Way Down
Tuples All the Way Down
 
Introduction to scala
Introduction to scalaIntroduction to scala
Introduction to scala
 
Scala introduction
Scala introductionScala introduction
Scala introduction
 
Arrays
ArraysArrays
Arrays
 
Softshake 2013: 10 reasons why java developers are jealous of Scala developers
Softshake 2013: 10 reasons why java developers are jealous of Scala developersSoftshake 2013: 10 reasons why java developers are jealous of Scala developers
Softshake 2013: 10 reasons why java developers are jealous of Scala developers
 
bobok
bobokbobok
bobok
 

More from Marcelo Cure

SciPy - Scientific Computing Tool
SciPy - Scientific Computing ToolSciPy - Scientific Computing Tool
SciPy - Scientific Computing Tool
Marcelo Cure
 
Test driven development
Test driven developmentTest driven development
Test driven development
Marcelo Cure
 
Apache lucene - full text search
Apache lucene - full text searchApache lucene - full text search
Apache lucene - full text search
Marcelo Cure
 

More from Marcelo Cure (16)

Api design
Api designApi design
Api design
 
Zero mq
Zero mqZero mq
Zero mq
 
Dev ops engineering and chatbots
Dev ops engineering and chatbotsDev ops engineering and chatbots
Dev ops engineering and chatbots
 
Versioning APIs
Versioning APIsVersioning APIs
Versioning APIs
 
Building restful ap is with harvester js
Building restful ap is with harvester jsBuilding restful ap is with harvester js
Building restful ap is with harvester js
 
Cqrs, event sourcing and microservices
Cqrs, event sourcing and microservicesCqrs, event sourcing and microservices
Cqrs, event sourcing and microservices
 
Immutability and immutable js
Immutability and immutable jsImmutability and immutable js
Immutability and immutable js
 
Functional programming with python
Functional programming with pythonFunctional programming with python
Functional programming with python
 
Polymer
PolymerPolymer
Polymer
 
Hexagonal Architecture
Hexagonal ArchitectureHexagonal Architecture
Hexagonal Architecture
 
What's the value of the metrics
What's the value of the metricsWhat's the value of the metrics
What's the value of the metrics
 
SciPy - Scientific Computing Tool
SciPy - Scientific Computing ToolSciPy - Scientific Computing Tool
SciPy - Scientific Computing Tool
 
Test driven development
Test driven developmentTest driven development
Test driven development
 
Usability testing
Usability testingUsability testing
Usability testing
 
Corona
CoronaCorona
Corona
 
Apache lucene - full text search
Apache lucene - full text searchApache lucene - full text search
Apache lucene - full text search
 

Recently uploaded

Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Medical / Health Care (+971588192166) Mifepristone and Misoprostol tablets 200mg
 

Recently uploaded (20)

Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptx
 
WSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaSWSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaS
 
WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...
WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...
WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...
 
WSO2Con2024 - Software Delivery in Hybrid Environments
WSO2Con2024 - Software Delivery in Hybrid EnvironmentsWSO2Con2024 - Software Delivery in Hybrid Environments
WSO2Con2024 - Software Delivery in Hybrid Environments
 
WSO2CON2024 - Why Should You Consider Ballerina for Your Next Integration
WSO2CON2024 - Why Should You Consider Ballerina for Your Next IntegrationWSO2CON2024 - Why Should You Consider Ballerina for Your Next Integration
WSO2CON2024 - Why Should You Consider Ballerina for Your Next Integration
 
WSO2CON 2024 Slides - Unlocking Value with AI
WSO2CON 2024 Slides - Unlocking Value with AIWSO2CON 2024 Slides - Unlocking Value with AI
WSO2CON 2024 Slides - Unlocking Value with AI
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
 
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
 
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open SourceWSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
 
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public Administration
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public AdministrationWSO2CON 2024 - How CSI Piemonte Is Apifying the Public Administration
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public Administration
 
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the past
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
 
WSO2Con2024 - Unleashing the Financial Potential of 13 Million People
WSO2Con2024 - Unleashing the Financial Potential of 13 Million PeopleWSO2Con2024 - Unleashing the Financial Potential of 13 Million People
WSO2Con2024 - Unleashing the Financial Potential of 13 Million People
 
WSO2CON 2024 - Not Just Microservices: Rightsize Your Services!
WSO2CON 2024 - Not Just Microservices: Rightsize Your Services!WSO2CON 2024 - Not Just Microservices: Rightsize Your Services!
WSO2CON 2024 - Not Just Microservices: Rightsize Your Services!
 
WSO2Con2024 - Low-Code Integration Tooling
WSO2Con2024 - Low-Code Integration ToolingWSO2Con2024 - Low-Code Integration Tooling
WSO2Con2024 - Low-Code Integration Tooling
 
WSO2CON 2024 - Architecting AI in the Enterprise: APIs and Applications
WSO2CON 2024 - Architecting AI in the Enterprise: APIs and ApplicationsWSO2CON 2024 - Architecting AI in the Enterprise: APIs and Applications
WSO2CON 2024 - Architecting AI in the Enterprise: APIs and Applications
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go Platformless
 

Scala

  • 2. WTF is Scala?  Multi-paradigm programming lang  Created on 2003 by Martin Odersky  Based on Java  Compiled into Java Byte Code  Runs under JVM  Integration with Java
  • 3. Functional Paradigm  Executed evaluating expressions  Avoids using mutable state  Functions treated as values(can be passed as functions)  No side effects  Expressiveness  Less Bugs  Simpler  Less code
  • 5. List manipulation scala> val list = (1 to 12).toList list: List[Int] = List(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12) scala> list.filter(_ % 2 == 0) res1: List[Int] = List(2, 4, 6, 8, 10, 12) scala> val list = (1 to 12).toList list: List[Int] = List(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12) scala> val list2 = list.map(_ * 2) list2: List[Int] = List(2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24) scala> list2.reduceLeft(_ + _) res2: Int = 156
  • 6. FlatMaps scala> val fruits = Seq("apple", "banana", "orange") fruits: Seq[String] = List(apple, banana, orange) scala> fruits.flatMap(_.toUpperCase) res13: Seq[Char] = List(A, P, P, L, E, B, A, N, A, N, A, O, R, A, N, G, E)
  • 7. Anonymous Functions scala> var sum = (x:Int,y:Int) => x + y sum: (Int, Int) => Int = <function2> scala> sum(1,2) res3: Int = 3
  • 8. Pattern Matching scala> def toYesOrNo(choice: Int): String = choice match { | case 1 => "yes" | case 0 => "no" | case _ => "error" | } toYesOrNo: (choice: Int)String scala> println(toYesOrNo(1)) yes scala> println(toYesOrNo(0)) no scala> println(toYesOrNo(3)) error
  • 9. Case Class  Plain and immutable data-holding objects  Depends exclusively on its constructor arguments. scala> case class Node(left: Int, right: Int) defined class Node scala> var node1 = Node(1,2) node1: Node = Node(1,2)
  • 10. High Order Functions  Takes other functions as parameter  Return functions scala> def apply(f: Int => String, v: Int) = f(v) apply: (f: Int => String, v: Int)String scala> def layout[A](x: A) = "[" + x.toString() + "]" layout: [A](x: A)String scala> println( apply( layout, 10) ) [10]
  • 11. Web Frameworks  Lift Framework  Play framework  Bowler framework
  • 12. End