SlideShare ist ein Scribd-Unternehmen logo
1 von 21
Downloaden Sie, um offline zu lesen
Getting Functional with Scala
An Introduction to Functional Programming and the Scala Programming Language
September, 2016
2
Software Engineer at IBM Mobile Innovation Lab
@jorgelpaez19
Jorge Paez
3
My IBM Journey… So far
www-01.ibm.com/employment/us/extremeblue https://www.ibm.com/innovation/milab/
4
Where will yours start?
http://www-03.ibm.com/employment/entrylevel_campus.html
5
What is Functional Programming?
6
Function Not a Function
7
Core Ideas
• Data is immutable
• PURE function are our basic building block
• Use expressions over instructions
• First class functions
• Type-strictness
8
…but why?
9
Benefits!
• Simpler concurrency/parallelism
• Optimizations with caching or memoization
• Easier debugging
• Cleaner/less verbose code
• Encourages code re-use
• Promotes Test Driven Development
10
Pure vs Impure
// In Main.java
public String getFormal(String name) {

name = "Mr." + name;

return name;

}
// In Main.scala
def getFormal(name: String) = s"Mr. $name!"
11
Expressions vs Instructions
// In Main.java
public double[] convertToMeters(double[] measurements) {

double[] metricMeasurements = 

new double[measurements.length];



for(int i = 0; i < measurements.length; ++i) {

metricMeasurements[i] =

measurements[i] * CONVERSION_FACTOR;

}



return metricMeasurements;

}
// In Main.scala
def convertToMeters(measurements: Seq[Double]) =

measurements.map(n => n * CONVERSION_FACTOR)
12
First Class Functions
def main(args: Array[String]): Unit = {

draw(getCurve(0, 90), 1)

draw(getCurve, 2)

}



def getCurve: Double => Seq[(Double, Double)] =

(r) => (0 to 360).map(theta => getCartesianCoordinates(r, theta))



def getCurve(thetaO: Int, thetaF: Int): Double => Seq[(Double, Double)] =

(r) => (thetaO to thetaF).map(theta => getCartesianCoordinates(r, theta))



def getCartesianCoordinates(r: Double, theta: Double): (Double, Double) =

((r * Math.cos(theta)), (r * Math.sin(theta)))





def draw(func: Double => Seq[(Double, Double)], scale: Double)
13
First Class Functions
def main(args: Array[String]): Unit = {

draw(getCurve(0, 90), 1)

draw(getCurve, 2)

}



def getCurve: Double => Seq[(Double, Double)] =

(r) => (0 to 360).map(theta => getCartesianCoordinates(r, theta))



def getCurve(thetaO: Int, thetaF: Int): Double => Seq[(Double, Double)] =

(r) => (thetaO to thetaF).map(theta => getCartesianCoordinates(r, theta))



def getCartesianCoordinates(r: Double, theta: Double): (Double, Double) =

((r * Math.cos(theta)), (r * Math.sin(theta)))





def draw(func: Double => Seq[(Double, Double)], scale: Double)




def getCurve: Double => Seq[(Double, Double)] =

(r) => (0 to 360).map(theta => getCartesianCoordinates(r, theta))



def getCurve(thetaO: Int, thetaF: Int): Double => Seq[(Double, Double)] =

(r) => (thetaO to thetaF).map(theta => getCartesianCoordinates(r, theta))







14
First Class Functions
def main(args: Array[String]): Unit = {

draw(getCurve(0, 90), 1)

draw(getCurve, 2)

}



def getCurve: Double => Seq[(Double, Double)] =

(r) => (0 to 360).map(theta => getCartesianCoordinates(r, theta))



def getCurve(thetaO: Int, thetaF: Int): Double => Seq[(Double, Double)] =

(r) => (thetaO to thetaF).map(theta => getCartesianCoordinates(r, theta))



def getCartesianCoordinates(r: Double, theta: Double): (Double, Double) =

((r * Math.cos(theta)), (r * Math.sin(theta)))





def draw(func: Double => Seq[(Double, Double)], scale: Double)


def getCartesianCoordinates(r: Double, theta: Double): (Double, Double) =

((r * Math.cos(theta)), (r * Math.sin(theta)))



15
First Class Functions
def main(args: Array[String]): Unit = {

draw(getCurve(0, 90), 1)

draw(getCurve, 2)

}



def getCurve: Double => Seq[(Double, Double)] =

(r) => (0 to 360).map(theta => getCartesianCoordinates(r, theta))



def getCurve(thetaO: Int, thetaF: Int): Double => Seq[(Double, Double)] =

(r) => (thetaO to thetaF).map(theta => getCartesianCoordinates(r, theta))



def getCartesianCoordinates(r: Double, theta: Double): (Double, Double) =

((r * Math.cos(theta)), (r * Math.sin(theta)))





def draw(func: Double => Seq[(Double, Double)], scale: Double)
def main(args: Array[String]): Unit = {

draw(getCurve(0, 90), 1)

draw(getCurve, 2)

}





def draw(func: Double => Seq[(Double, Double)], scale: Double)
16
First Class Functions
def main(args: Array[String]): Unit = {

draw(getCurve(0, 90), 1)

draw(getCurve, 2)

}



def getCurve: Double => Seq[(Double, Double)] =

(r) => (0 to 360).map(theta => getCartesianCoordinates(r, theta))



def getCurve(thetaO: Int, thetaF: Int): Double => Seq[(Double, Double)] =

(r) => (thetaO to thetaF).map(theta => getCartesianCoordinates(r, theta))



def getCartesianCoordinates(r: Double, theta: Double): (Double, Double) =

((r * Math.cos(theta)), (r * Math.sin(theta)))





def draw(func: Double => Seq[(Double, Double)], scale: Double)
17
Type Strictness
sealed trait Person



case class Student(name: String) extends Person



case class Alumni(name: String) extends Person



def getBusFare(person : Person): Int = {

person match {

case p: Student => 0

case p: Alumni => 2

}

}
18
Options
// Form asking for person's gender

// a) Female

// b) Male

// c) Don’t want to disclose



def main(args: Array[String]): Unit = {

val answers = Seq(Some("Female"), Some("Male"), Some(null), None)



answers.map(a => a match {

case Some(gender) =>

if(gender == null){

"the didn't want to disclose his or her gender"

} else {

s"The user's gender is $gender"

}

case None => "the user didn't pick a value on the form"

})

}
19
What’s next?
20
Keep Learning
• Slides: http://www.slideshare.net/JorgePaez15/getting-functional-with-scala
• Deploying a Scala server to Bluemix: https://www.ibm.com/innovation/milab/how-
to-run-a-scala-web-app-on-ibm-bluemix/
• Free class: https://www.coursera.org/learn/progfun1
Thank You

@jorgelpaez19
@IBM_MIL

Weitere ähnliche Inhalte

Was ist angesagt?

GUL UC3M - Introduction to functional programming
GUL UC3M - Introduction to functional programmingGUL UC3M - Introduction to functional programming
GUL UC3M - Introduction to functional programmingDavid Muñoz Díaz
 
Python 101 language features and functional programming
Python 101 language features and functional programmingPython 101 language features and functional programming
Python 101 language features and functional programmingLukasz Dynowski
 
Data Structures in javaScript 2015
Data Structures in javaScript 2015Data Structures in javaScript 2015
Data Structures in javaScript 2015Nir Kaufman
 
R + Hadoop = Big Data Analytics. How Revolution Analytics' RHadoop Project Al...
R + Hadoop = Big Data Analytics. How Revolution Analytics' RHadoop Project Al...R + Hadoop = Big Data Analytics. How Revolution Analytics' RHadoop Project Al...
R + Hadoop = Big Data Analytics. How Revolution Analytics' RHadoop Project Al...Revolution Analytics
 
ITT 2015 - Saul Mora - Object Oriented Function Programming
ITT 2015 - Saul Mora - Object Oriented Function ProgrammingITT 2015 - Saul Mora - Object Oriented Function Programming
ITT 2015 - Saul Mora - Object Oriented Function ProgrammingIstanbul Tech Talks
 
How to extend map? Or why we need collections redesign? - Scalar 2017
How to extend map? Or why we need collections redesign? - Scalar 2017How to extend map? Or why we need collections redesign? - Scalar 2017
How to extend map? Or why we need collections redesign? - Scalar 2017Szymon Matejczyk
 
Taking your side effects aside
Taking your side effects asideTaking your side effects aside
Taking your side effects aside💡 Tomasz Kogut
 
Profiling and optimization
Profiling and optimizationProfiling and optimization
Profiling and optimizationg3_nittala
 
Beyond tf idf why, what & how
Beyond tf idf why, what & howBeyond tf idf why, what & how
Beyond tf idf why, what & howlucenerevolution
 
First-Class Patterns
First-Class PatternsFirst-Class Patterns
First-Class PatternsJohn De Goes
 
Side by Side - Scala and Java Adaptations of Martin Fowler’s Javascript Refac...
Side by Side - Scala and Java Adaptations of Martin Fowler’s Javascript Refac...Side by Side - Scala and Java Adaptations of Martin Fowler’s Javascript Refac...
Side by Side - Scala and Java Adaptations of Martin Fowler’s Javascript Refac...Philip Schwarz
 
The best language in the world
The best language in the worldThe best language in the world
The best language in the worldDavid Muñoz Díaz
 
ZIO Schedule: Conquering Flakiness & Recurrence with Pure Functional Programming
ZIO Schedule: Conquering Flakiness & Recurrence with Pure Functional ProgrammingZIO Schedule: Conquering Flakiness & Recurrence with Pure Functional Programming
ZIO Schedule: Conquering Flakiness & Recurrence with Pure Functional ProgrammingJohn De Goes
 
Introduction to Monads in Scala (2)
Introduction to Monads in Scala (2)Introduction to Monads in Scala (2)
Introduction to Monads in Scala (2)stasimus
 
Principled Error Handling with FP
Principled Error Handling with FPPrincipled Error Handling with FP
Principled Error Handling with FPLuka Jacobowitz
 
Scala. Introduction to FP. Monads
Scala. Introduction to FP. MonadsScala. Introduction to FP. Monads
Scala. Introduction to FP. MonadsKirill Kozlov
 
Python Performance 101
Python Performance 101Python Performance 101
Python Performance 101Ankur Gupta
 
Делаем пользовательское Api на базе Shapeless
Делаем пользовательское Api на базе ShapelessДелаем пользовательское Api на базе Shapeless
Делаем пользовательское Api на базе ShapelessВадим Челышов
 
[Let'Swift 2019] 실용적인 함수형 프로그래밍 워크샵
[Let'Swift 2019] 실용적인 함수형 프로그래밍 워크샵[Let'Swift 2019] 실용적인 함수형 프로그래밍 워크샵
[Let'Swift 2019] 실용적인 함수형 프로그래밍 워크샵Wanbok Choi
 

Was ist angesagt? (20)

GUL UC3M - Introduction to functional programming
GUL UC3M - Introduction to functional programmingGUL UC3M - Introduction to functional programming
GUL UC3M - Introduction to functional programming
 
Python 101 language features and functional programming
Python 101 language features and functional programmingPython 101 language features and functional programming
Python 101 language features and functional programming
 
Data Structures in javaScript 2015
Data Structures in javaScript 2015Data Structures in javaScript 2015
Data Structures in javaScript 2015
 
R + Hadoop = Big Data Analytics. How Revolution Analytics' RHadoop Project Al...
R + Hadoop = Big Data Analytics. How Revolution Analytics' RHadoop Project Al...R + Hadoop = Big Data Analytics. How Revolution Analytics' RHadoop Project Al...
R + Hadoop = Big Data Analytics. How Revolution Analytics' RHadoop Project Al...
 
ITT 2015 - Saul Mora - Object Oriented Function Programming
ITT 2015 - Saul Mora - Object Oriented Function ProgrammingITT 2015 - Saul Mora - Object Oriented Function Programming
ITT 2015 - Saul Mora - Object Oriented Function Programming
 
How to extend map? Or why we need collections redesign? - Scalar 2017
How to extend map? Or why we need collections redesign? - Scalar 2017How to extend map? Or why we need collections redesign? - Scalar 2017
How to extend map? Or why we need collections redesign? - Scalar 2017
 
Taking your side effects aside
Taking your side effects asideTaking your side effects aside
Taking your side effects aside
 
Profiling and optimization
Profiling and optimizationProfiling and optimization
Profiling and optimization
 
Beyond tf idf why, what & how
Beyond tf idf why, what & howBeyond tf idf why, what & how
Beyond tf idf why, what & how
 
First-Class Patterns
First-Class PatternsFirst-Class Patterns
First-Class Patterns
 
Side by Side - Scala and Java Adaptations of Martin Fowler’s Javascript Refac...
Side by Side - Scala and Java Adaptations of Martin Fowler’s Javascript Refac...Side by Side - Scala and Java Adaptations of Martin Fowler’s Javascript Refac...
Side by Side - Scala and Java Adaptations of Martin Fowler’s Javascript Refac...
 
The best language in the world
The best language in the worldThe best language in the world
The best language in the world
 
ZIO Schedule: Conquering Flakiness & Recurrence with Pure Functional Programming
ZIO Schedule: Conquering Flakiness & Recurrence with Pure Functional ProgrammingZIO Schedule: Conquering Flakiness & Recurrence with Pure Functional Programming
ZIO Schedule: Conquering Flakiness & Recurrence with Pure Functional Programming
 
08. haskell Functions
08. haskell Functions08. haskell Functions
08. haskell Functions
 
Introduction to Monads in Scala (2)
Introduction to Monads in Scala (2)Introduction to Monads in Scala (2)
Introduction to Monads in Scala (2)
 
Principled Error Handling with FP
Principled Error Handling with FPPrincipled Error Handling with FP
Principled Error Handling with FP
 
Scala. Introduction to FP. Monads
Scala. Introduction to FP. MonadsScala. Introduction to FP. Monads
Scala. Introduction to FP. Monads
 
Python Performance 101
Python Performance 101Python Performance 101
Python Performance 101
 
Делаем пользовательское Api на базе Shapeless
Делаем пользовательское Api на базе ShapelessДелаем пользовательское Api на базе Shapeless
Делаем пользовательское Api на базе Shapeless
 
[Let'Swift 2019] 실용적인 함수형 프로그래밍 워크샵
[Let'Swift 2019] 실용적인 함수형 프로그래밍 워크샵[Let'Swift 2019] 실용적인 함수형 프로그래밍 워크샵
[Let'Swift 2019] 실용적인 함수형 프로그래밍 워크샵
 

Andere mochten auch

Übersicht Glm Workshop 2009
Übersicht Glm Workshop 2009Übersicht Glm Workshop 2009
Übersicht Glm Workshop 2009Mark Heckmann
 
Neural networks1
Neural networks1Neural networks1
Neural networks1Mohan Raj
 
Maven c'est bien, SBT c'est mieux
Maven c'est bien, SBT c'est mieuxMaven c'est bien, SBT c'est mieux
Maven c'est bien, SBT c'est mieuxFabrice Sznajderman
 
Introduction to R programming
Introduction to R programmingIntroduction to R programming
Introduction to R programmingVictor Ordu
 
Introduction à Scala - Michel Schinz - January 2010
Introduction à Scala - Michel Schinz - January 2010Introduction à Scala - Michel Schinz - January 2010
Introduction à Scala - Michel Schinz - January 2010JUG Lausanne
 
Scala in Action - Heiko Seeburger
Scala in Action - Heiko SeeburgerScala in Action - Heiko Seeburger
Scala in Action - Heiko SeeburgerJAX London
 
Paris stormusergroup intrudocution
Paris stormusergroup intrudocutionParis stormusergroup intrudocution
Paris stormusergroup intrudocutionParis_Storm_UG
 
Introduction to Spark with Scala
Introduction to Spark with ScalaIntroduction to Spark with Scala
Introduction to Spark with ScalaHimanshu Gupta
 
Scala - A Scalable Language
Scala - A Scalable LanguageScala - A Scalable Language
Scala - A Scalable LanguageMario Gleichmann
 
Scala at HUJI PL Seminar 2008
Scala at HUJI PL Seminar 2008Scala at HUJI PL Seminar 2008
Scala at HUJI PL Seminar 2008Yardena Meymann
 
Mémoire de fin d'étude - La big data et les réseaux sociaux
Mémoire de fin d'étude - La big data et les réseaux sociauxMémoire de fin d'étude - La big data et les réseaux sociaux
Mémoire de fin d'étude - La big data et les réseaux sociauxChloé Marty
 

Andere mochten auch (20)

Übersicht Glm Workshop 2009
Übersicht Glm Workshop 2009Übersicht Glm Workshop 2009
Übersicht Glm Workshop 2009
 
Neural networks1
Neural networks1Neural networks1
Neural networks1
 
Maven c'est bien, SBT c'est mieux
Maven c'est bien, SBT c'est mieuxMaven c'est bien, SBT c'est mieux
Maven c'est bien, SBT c'est mieux
 
Universitélang scala tools
Universitélang scala toolsUniversitélang scala tools
Universitélang scala tools
 
Les monades Scala, Java 8
Les monades Scala, Java 8Les monades Scala, Java 8
Les monades Scala, Java 8
 
Introduction to R programming
Introduction to R programmingIntroduction to R programming
Introduction to R programming
 
Université des langages scala
Université des langages   scalaUniversité des langages   scala
Université des langages scala
 
Scala Intro
Scala IntroScala Intro
Scala Intro
 
Lagom, reactive framework
Lagom, reactive frameworkLagom, reactive framework
Lagom, reactive framework
 
Simulation presentation
Simulation presentationSimulation presentation
Simulation presentation
 
Introduction à Scala - Michel Schinz - January 2010
Introduction à Scala - Michel Schinz - January 2010Introduction à Scala - Michel Schinz - January 2010
Introduction à Scala - Michel Schinz - January 2010
 
Scala in Action - Heiko Seeburger
Scala in Action - Heiko SeeburgerScala in Action - Heiko Seeburger
Scala in Action - Heiko Seeburger
 
Paris stormusergroup intrudocution
Paris stormusergroup intrudocutionParis stormusergroup intrudocution
Paris stormusergroup intrudocution
 
An Intoduction to R
An Intoduction to RAn Intoduction to R
An Intoduction to R
 
Introduction to Spark with Scala
Introduction to Spark with ScalaIntroduction to Spark with Scala
Introduction to Spark with Scala
 
Hammurabi
HammurabiHammurabi
Hammurabi
 
Soutenance ysance
Soutenance ysanceSoutenance ysance
Soutenance ysance
 
Scala - A Scalable Language
Scala - A Scalable LanguageScala - A Scalable Language
Scala - A Scalable Language
 
Scala at HUJI PL Seminar 2008
Scala at HUJI PL Seminar 2008Scala at HUJI PL Seminar 2008
Scala at HUJI PL Seminar 2008
 
Mémoire de fin d'étude - La big data et les réseaux sociaux
Mémoire de fin d'étude - La big data et les réseaux sociauxMémoire de fin d'étude - La big data et les réseaux sociaux
Mémoire de fin d'étude - La big data et les réseaux sociaux
 

Ähnlich wie Getting Functional with Scala: An Intro to FP & Scala Lang

Refactoring to Macros with Clojure
Refactoring to Macros with ClojureRefactoring to Macros with Clojure
Refactoring to Macros with ClojureDmitry Buzdin
 
Fosdem2017 Scientific computing on Jruby
Fosdem2017  Scientific computing on JrubyFosdem2017  Scientific computing on Jruby
Fosdem2017 Scientific computing on JrubyPrasun Anand
 
GECon2017_Cpp a monster that no one likes but that will outlast them all _Ya...
GECon2017_Cpp  a monster that no one likes but that will outlast them all _Ya...GECon2017_Cpp  a monster that no one likes but that will outlast them all _Ya...
GECon2017_Cpp a monster that no one likes but that will outlast them all _Ya...GECon_Org Team
 
GECon 2017: C++ - a Monster that no one likes but that will outlast them all
GECon 2017: C++ - a Monster that no one likes but that will outlast them allGECon 2017: C++ - a Monster that no one likes but that will outlast them all
GECon 2017: C++ - a Monster that no one likes but that will outlast them allYauheni Akhotnikau
 
A Recovering Java Developer Learns to Go
A Recovering Java Developer Learns to GoA Recovering Java Developer Learns to Go
A Recovering Java Developer Learns to GoMatt Stine
 
Scala introduction
Scala introductionScala introduction
Scala introductionvito jeng
 
Rainer Grimm, “Functional Programming in C++11”
Rainer Grimm, “Functional Programming in C++11”Rainer Grimm, “Functional Programming in C++11”
Rainer Grimm, “Functional Programming in C++11”Platonov Sergey
 
PyData NYC 2019
PyData NYC 2019PyData NYC 2019
PyData NYC 2019Li Jin
 
Emerging Languages: A Tour of the Horizon
Emerging Languages: A Tour of the HorizonEmerging Languages: A Tour of the Horizon
Emerging Languages: A Tour of the HorizonAlex Payne
 
CoffeeScript - A Rubyist's Love Affair
CoffeeScript - A Rubyist's Love AffairCoffeeScript - A Rubyist's Love Affair
CoffeeScript - A Rubyist's Love AffairMark
 
Scala Days 2011 - Rogue: A Type-Safe DSL for MongoDB
Scala Days 2011 - Rogue: A Type-Safe DSL for MongoDBScala Days 2011 - Rogue: A Type-Safe DSL for MongoDB
Scala Days 2011 - Rogue: A Type-Safe DSL for MongoDBjorgeortiz85
 
Introduction to Scalding and Monoids
Introduction to Scalding and MonoidsIntroduction to Scalding and Monoids
Introduction to Scalding and MonoidsHugo Gävert
 
Writing DSL with Applicative Functors
Writing DSL with Applicative FunctorsWriting DSL with Applicative Functors
Writing DSL with Applicative FunctorsDavid Galichet
 
NetPonto - The Future Of C# - NetConf Edition
NetPonto - The Future Of C# - NetConf EditionNetPonto - The Future Of C# - NetConf Edition
NetPonto - The Future Of C# - NetConf EditionPaulo Morgado
 
Rcpp: Seemless R and C++
Rcpp: Seemless R and C++Rcpp: Seemless R and C++
Rcpp: Seemless R and C++Romain Francois
 
High performance GPU computing with Ruby RubyConf 2017
High performance GPU computing with Ruby  RubyConf 2017High performance GPU computing with Ruby  RubyConf 2017
High performance GPU computing with Ruby RubyConf 2017Prasun Anand
 

Ähnlich wie Getting Functional with Scala: An Intro to FP & Scala Lang (20)

Refactoring to Macros with Clojure
Refactoring to Macros with ClojureRefactoring to Macros with Clojure
Refactoring to Macros with Clojure
 
Fosdem2017 Scientific computing on Jruby
Fosdem2017  Scientific computing on JrubyFosdem2017  Scientific computing on Jruby
Fosdem2017 Scientific computing on Jruby
 
Scala in Places API
Scala in Places APIScala in Places API
Scala in Places API
 
GECon2017_Cpp a monster that no one likes but that will outlast them all _Ya...
GECon2017_Cpp  a monster that no one likes but that will outlast them all _Ya...GECon2017_Cpp  a monster that no one likes but that will outlast them all _Ya...
GECon2017_Cpp a monster that no one likes but that will outlast them all _Ya...
 
GECon 2017: C++ - a Monster that no one likes but that will outlast them all
GECon 2017: C++ - a Monster that no one likes but that will outlast them allGECon 2017: C++ - a Monster that no one likes but that will outlast them all
GECon 2017: C++ - a Monster that no one likes but that will outlast them all
 
A Recovering Java Developer Learns to Go
A Recovering Java Developer Learns to GoA Recovering Java Developer Learns to Go
A Recovering Java Developer Learns to Go
 
Scala introduction
Scala introductionScala introduction
Scala introduction
 
Rainer Grimm, “Functional Programming in C++11”
Rainer Grimm, “Functional Programming in C++11”Rainer Grimm, “Functional Programming in C++11”
Rainer Grimm, “Functional Programming in C++11”
 
PyData NYC 2019
PyData NYC 2019PyData NYC 2019
PyData NYC 2019
 
Emerging Languages: A Tour of the Horizon
Emerging Languages: A Tour of the HorizonEmerging Languages: A Tour of the Horizon
Emerging Languages: A Tour of the Horizon
 
CoffeeScript - A Rubyist's Love Affair
CoffeeScript - A Rubyist's Love AffairCoffeeScript - A Rubyist's Love Affair
CoffeeScript - A Rubyist's Love Affair
 
TreSQL
TreSQL TreSQL
TreSQL
 
Scala Days 2011 - Rogue: A Type-Safe DSL for MongoDB
Scala Days 2011 - Rogue: A Type-Safe DSL for MongoDBScala Days 2011 - Rogue: A Type-Safe DSL for MongoDB
Scala Days 2011 - Rogue: A Type-Safe DSL for MongoDB
 
Angular2 for Beginners
Angular2 for BeginnersAngular2 for Beginners
Angular2 for Beginners
 
Introduction to Scalding and Monoids
Introduction to Scalding and MonoidsIntroduction to Scalding and Monoids
Introduction to Scalding and Monoids
 
Writing DSL with Applicative Functors
Writing DSL with Applicative FunctorsWriting DSL with Applicative Functors
Writing DSL with Applicative Functors
 
NetPonto - The Future Of C# - NetConf Edition
NetPonto - The Future Of C# - NetConf EditionNetPonto - The Future Of C# - NetConf Edition
NetPonto - The Future Of C# - NetConf Edition
 
Rcpp: Seemless R and C++
Rcpp: Seemless R and C++Rcpp: Seemless R and C++
Rcpp: Seemless R and C++
 
Dive into PySpark
Dive into PySparkDive into PySpark
Dive into PySpark
 
High performance GPU computing with Ruby RubyConf 2017
High performance GPU computing with Ruby  RubyConf 2017High performance GPU computing with Ruby  RubyConf 2017
High performance GPU computing with Ruby RubyConf 2017
 

Kürzlich hochgeladen

CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️anilsa9823
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about usDynamic Netsoft
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AIABDERRAOUF MEHENNI
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionSolGuruz
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfjoe51371421
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...OnePlan Solutions
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 

Kürzlich hochgeladen (20)

CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about us
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdf
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 

Getting Functional with Scala: An Intro to FP & Scala Lang

  • 1. Getting Functional with Scala An Introduction to Functional Programming and the Scala Programming Language September, 2016
  • 2. 2 Software Engineer at IBM Mobile Innovation Lab @jorgelpaez19 Jorge Paez
  • 3. 3 My IBM Journey… So far www-01.ibm.com/employment/us/extremeblue https://www.ibm.com/innovation/milab/
  • 4. 4 Where will yours start? http://www-03.ibm.com/employment/entrylevel_campus.html
  • 5. 5 What is Functional Programming?
  • 6. 6 Function Not a Function
  • 7. 7 Core Ideas • Data is immutable • PURE function are our basic building block • Use expressions over instructions • First class functions • Type-strictness
  • 9. 9 Benefits! • Simpler concurrency/parallelism • Optimizations with caching or memoization • Easier debugging • Cleaner/less verbose code • Encourages code re-use • Promotes Test Driven Development
  • 10. 10 Pure vs Impure // In Main.java public String getFormal(String name) {
 name = "Mr." + name;
 return name;
 } // In Main.scala def getFormal(name: String) = s"Mr. $name!"
  • 11. 11 Expressions vs Instructions // In Main.java public double[] convertToMeters(double[] measurements) {
 double[] metricMeasurements = 
 new double[measurements.length];
 
 for(int i = 0; i < measurements.length; ++i) {
 metricMeasurements[i] =
 measurements[i] * CONVERSION_FACTOR;
 }
 
 return metricMeasurements;
 } // In Main.scala def convertToMeters(measurements: Seq[Double]) =
 measurements.map(n => n * CONVERSION_FACTOR)
  • 12. 12 First Class Functions def main(args: Array[String]): Unit = {
 draw(getCurve(0, 90), 1)
 draw(getCurve, 2)
 }
 
 def getCurve: Double => Seq[(Double, Double)] =
 (r) => (0 to 360).map(theta => getCartesianCoordinates(r, theta))
 
 def getCurve(thetaO: Int, thetaF: Int): Double => Seq[(Double, Double)] =
 (r) => (thetaO to thetaF).map(theta => getCartesianCoordinates(r, theta))
 
 def getCartesianCoordinates(r: Double, theta: Double): (Double, Double) =
 ((r * Math.cos(theta)), (r * Math.sin(theta)))
 
 
 def draw(func: Double => Seq[(Double, Double)], scale: Double)
  • 13. 13 First Class Functions def main(args: Array[String]): Unit = {
 draw(getCurve(0, 90), 1)
 draw(getCurve, 2)
 }
 
 def getCurve: Double => Seq[(Double, Double)] =
 (r) => (0 to 360).map(theta => getCartesianCoordinates(r, theta))
 
 def getCurve(thetaO: Int, thetaF: Int): Double => Seq[(Double, Double)] =
 (r) => (thetaO to thetaF).map(theta => getCartesianCoordinates(r, theta))
 
 def getCartesianCoordinates(r: Double, theta: Double): (Double, Double) =
 ((r * Math.cos(theta)), (r * Math.sin(theta)))
 
 
 def draw(func: Double => Seq[(Double, Double)], scale: Double) 
 
 def getCurve: Double => Seq[(Double, Double)] =
 (r) => (0 to 360).map(theta => getCartesianCoordinates(r, theta))
 
 def getCurve(thetaO: Int, thetaF: Int): Double => Seq[(Double, Double)] =
 (r) => (thetaO to thetaF).map(theta => getCartesianCoordinates(r, theta))
 
 
 

  • 14. 14 First Class Functions def main(args: Array[String]): Unit = {
 draw(getCurve(0, 90), 1)
 draw(getCurve, 2)
 }
 
 def getCurve: Double => Seq[(Double, Double)] =
 (r) => (0 to 360).map(theta => getCartesianCoordinates(r, theta))
 
 def getCurve(thetaO: Int, thetaF: Int): Double => Seq[(Double, Double)] =
 (r) => (thetaO to thetaF).map(theta => getCartesianCoordinates(r, theta))
 
 def getCartesianCoordinates(r: Double, theta: Double): (Double, Double) =
 ((r * Math.cos(theta)), (r * Math.sin(theta)))
 
 
 def draw(func: Double => Seq[(Double, Double)], scale: Double) 
 def getCartesianCoordinates(r: Double, theta: Double): (Double, Double) =
 ((r * Math.cos(theta)), (r * Math.sin(theta)))
 

  • 15. 15 First Class Functions def main(args: Array[String]): Unit = {
 draw(getCurve(0, 90), 1)
 draw(getCurve, 2)
 }
 
 def getCurve: Double => Seq[(Double, Double)] =
 (r) => (0 to 360).map(theta => getCartesianCoordinates(r, theta))
 
 def getCurve(thetaO: Int, thetaF: Int): Double => Seq[(Double, Double)] =
 (r) => (thetaO to thetaF).map(theta => getCartesianCoordinates(r, theta))
 
 def getCartesianCoordinates(r: Double, theta: Double): (Double, Double) =
 ((r * Math.cos(theta)), (r * Math.sin(theta)))
 
 
 def draw(func: Double => Seq[(Double, Double)], scale: Double) def main(args: Array[String]): Unit = {
 draw(getCurve(0, 90), 1)
 draw(getCurve, 2)
 }
 
 
 def draw(func: Double => Seq[(Double, Double)], scale: Double)
  • 16. 16 First Class Functions def main(args: Array[String]): Unit = {
 draw(getCurve(0, 90), 1)
 draw(getCurve, 2)
 }
 
 def getCurve: Double => Seq[(Double, Double)] =
 (r) => (0 to 360).map(theta => getCartesianCoordinates(r, theta))
 
 def getCurve(thetaO: Int, thetaF: Int): Double => Seq[(Double, Double)] =
 (r) => (thetaO to thetaF).map(theta => getCartesianCoordinates(r, theta))
 
 def getCartesianCoordinates(r: Double, theta: Double): (Double, Double) =
 ((r * Math.cos(theta)), (r * Math.sin(theta)))
 
 
 def draw(func: Double => Seq[(Double, Double)], scale: Double)
  • 17. 17 Type Strictness sealed trait Person
 
 case class Student(name: String) extends Person
 
 case class Alumni(name: String) extends Person
 
 def getBusFare(person : Person): Int = {
 person match {
 case p: Student => 0
 case p: Alumni => 2
 }
 }
  • 18. 18 Options // Form asking for person's gender
 // a) Female
 // b) Male
 // c) Don’t want to disclose
 
 def main(args: Array[String]): Unit = {
 val answers = Seq(Some("Female"), Some("Male"), Some(null), None)
 
 answers.map(a => a match {
 case Some(gender) =>
 if(gender == null){
 "the didn't want to disclose his or her gender"
 } else {
 s"The user's gender is $gender"
 }
 case None => "the user didn't pick a value on the form"
 })
 }
  • 20. 20 Keep Learning • Slides: http://www.slideshare.net/JorgePaez15/getting-functional-with-scala • Deploying a Scala server to Bluemix: https://www.ibm.com/innovation/milab/how- to-run-a-scala-web-app-on-ibm-bluemix/ • Free class: https://www.coursera.org/learn/progfun1