introduction to functional programming in scala
DESCRIPTION
Presentation from my talk at JEEConf (http://jeeconf.com) in Kiev, Ukraine on 24th of May, 2013TRANSCRIPT
Functional Programming with ScalaIntroduction by @JacekLaskowski
HTTPS://GITHUB.COM/PCHIUSANO/FPINSCALA
HTTPS://WWW.COURSERA.ORG/COURSE/PROGFUN
Functional programmingIn computer science, functional programming
is a programming paradigm that treats computation as the evaluation of
mathematical functions and avoids state and mutable data. It emphasizes the application of
functions, in contrast to the imperative programming style, which emphasizes changes in state.
HTTP://EN.WIKIPEDIA.ORG/WIKI/FUNCTIONAL_PROGRAMMING
Functional programming•Programming paradigm
•Computation = function evaluation
•Avoids state and mutable data
•Function composition
•Expressions everywhere
Scala is a modern multi-paradigm programming language designed to express common programming patterns in a concise, elegant, and type-safe way. It smoothly integrates features of object-oriented and functional languages.
HTTP://WWW.SCALA-LANG.ORG/NODE/104
Scala is also a functional language in the sense that every function is a value.
Keyword to define a Method
Method’s name
Method’s input parameters and
their typesMethod’s
return type (optional)
Method’s body
Expression vs statement
•A statement changes state•it’s called for side effects
•An expression produces result
FROM “ATOMIC SCALA” BY BRUCE ECKEL AND DIANNE MARSH
Everything in Scala is an expression
Is this an expression?
YES!Is this an expression?
YES!
Type => TypeFunction type
Function type examples
•Int => String•(Int, Int) => Int•Int => Int => Int•(Int => Int) => Int
Scala REPL
Collections in Scala
•Vector
•Set
•Map
•Range
Functional trio
•map
•filter
•reduce (foldLeft + foldRight)
Function literal
Function composition
Jacek Laskowski@JacekLaskowskihttp://blog.japila.pl
Pitannja?