SlideShare una empresa de Scribd logo
1 de 103
Descargar para leer sin conexión
SCALA
Functional domain
#cododajnia
Bartosz Kosarzycki
@bkosarzyckiMar 26, 2018
Outline
- SCALA introduction
- SCALA compared to other JVM languages / Kotlin vs SCALA
- Basic SCALA syntax
- Build tools - gradle/SBT
- Lambda calculus
- Functional programming
- Currying
- Pattern matching
- Lazy evaluation
- Scalaz
SCALA runs on:
Recommended IDEs:
Interactive playground:
https://scastie.scala-lang.org
TIOBE index (march 2018):
Language index
Java 1
C++ 3
JavaScript 8
Swift 12
Go 17
Dart 22
Scala 30
Kotlin 38
Bash 43
Companies using SCALA
Company Purpose
Twitter throughout the company, own utils
LinkedIn Scalatra microframework
Airbnb Aerosolve - open source machine learning software
Zalando Entire technology stack
Walmart Canada Backend platform
SoundCloud Finagle (micro services), Scalding and Spark (data
processing)
Google Firebase (parts), Nest
Verizon Quiver (multi-graphs), utils, whole tech. stack
Others: Siemens, Sony Pictures, Imageworks, Duolingo...
History of SCALA
- Designed by Martin Odersky (who worked on Java generics in
J2SE 5.0, and Pizza - Java with Generics, function pointers,
case-classes, pattern-matching)
- Released in 2003
- In May Odersky launches Typesafe Inc. (now - Lightbend Inc.)
which provides commercial support for Scala
- Scala is one of the few languages developed in close collaboration
with university society (technically “in the Academia”)
- As of now - Scala 2.12.4, increased performance
- SCALA = Java (OO) + Pizza + functional programming focus
* OO - Object Oriented Language
JVM languages
Road to functional programming - SCALA
- Seamless integration of functional programming features into an
otherwise object-oriented language
- “scala” - name comes from the ability to scale along with the
growing complexity of the project
- concurrent - ready for multi-core, micro-service world
Road to functional programming - SCALA
Non-functional Functional
Kotlin vs SCALA
SCALA Kotlin
Java interoperability Java code from Scala (100%)
Scala code from Java (edge
cases not supported)
bidirectional, 100%
Pattern matching yes, better yes
Design designed in the Academia designed by a leading
software/IDE company
Operator overloading yes, better
+ operator looking functions
yes
Compilation slower faster
Community bigger smaller (still relatively new)
Backward compatibility no yes (up to this point)
Kotlin vs SCALA
Scala has the right features, but its most obvious
deficiency is very slow compilation," said Dmitry Jemerov,
JetBrains development lead
Kotlin vs SCALA
Kotlin is a Better Java
- excellent tools
- syntactic sugar
- performance
- compatibility
- simple rather than formal
SCALA is more powerful than Java
- designed to do things Java cannot
- pattern matching
- monads
- traits
- full-blown closures
etc.
SCALA
BASIC SYNTAX
Classes and Objects
class Car {
def startEngine(): Unit = {
engine.invokeIgnition()
}
def openDoor(): Unit = {
}
}
object Car {
def build(color: Color): Car = {
new Car().withColor(color)
}
val RED = Color.fromHex(“#FF0000”)
}
Methods
class Car {
val engine = new Engine()
def startEngine(): Unit = {
engine.invokeIgnition();
}
def stopEngine = engine.stop
}
- {} are optional
- ; are optional
- () are optional
- return value is optional
- ‘return’ keyword is optional
- whole class body is a ‘constructor’
(functional domain/everything is a func)
- multiple parameter lists [this will exaplained later]
def multiply(x:Int)(y:Int): Int = x * y
Method arguments
add({
val res = 33 + 66
println(res)
res
}, 2)
def multiply (elems: Int*): Int = {
elems.foldLeft( 0)((accum, element) =>
accum * element)
}
Multiple classes in a file + inner classes
class Graph {
class Node {
var connectedNodes: List[Node] = Nil
}
}
class Tree
Postfix operator notation
List(1,2,3) head
2 + 2
2.+(2)
Build systems for SCALA
SBT
- performance
- SBT shell
- “Scala build tool”
GRADLE
- possible
- more configuration needed
- gradle 4.6 Scala Plugin - link
Build tools: Gradle
- Install gradle
(brew on macos/apt-get ubuntu)
- Run initialization script
- Import build.gradle into
IntelliJ IDEA
- Add “.idea” & “.gradle” to
.gitignore
Repository: link
Branch: feature/gradle-build-tool
$> gradle init --type scala-library
$> ./gradlew clean build
$> brew install gradle
Build tools: Gradle
Repository: link
Branch: feature/gradle-build-tool
class Application {
def run(args: Array[String]): Unit = {
println("Hello world!" )
}
}
object Application extends App {
override def main(args: Array[String]): Unit = {
new Application().run(args)
}
}
Entry point
Build tools: Gradle
Repository: link
Branch: feature/gradle-build-tool
Build.gradle:
plugins {
// Apply the scala plugin to add support for Scala
id 'scala'
}
dependencies {
// Use Scala 2.11 in our library project
compile 'org.scala-lang:scala-library:2.11.8'
}
repositories {
jcenter()
}
EXERCISE 1
Create gradle project
$> gradle init --type scala-library
$> ./gradlew clean build$> brew install gradle
Build tools: SBT
- Install sbt
(brew install sbt / Linux: link)
- Check version: sbt sbtVersion
[1.1.1]
- run ‘scala new’ and name the project
‘cododajnia’
- Import build.sbt into
IntelliJ IDEA
- Add “.idea” to
gitignore
Repository: link
Branch: feature/sbt-build-tool
$> sbt new scala/hello-world.g8
$> cd cododajnia; sbt clean compile
$> brew install sbt
$> sbt sbtVersion
Build tools: SBT
Add “target/” & “project/target/” to .gitignore
Repository: link
Branch: feature/sbt-build-tool
object Main extends App {
println("Hello, World!")
}
Main object is added automatically:
scalaVersion := "2.12.4"
name := "hello-world"
organization := "ch.epfl.scala"
version := "1.0"
libraryDependencies += "org.typelevel" %% "cats-core" % "1.0.1"
EXERCISE 2
Create sbt project
$> brew install sbt
$> sbt new scala/hello-world.g8
$> cd cododajnia; sbt clean compile
FUNCTIONAL
PROGRAMMING
Functional programming
- computation as the evaluation of mathematical functions
- avoids mutable data, stateless
- expressions/declarations instead of statements
- originates from λ-calculus (lambda calculus)
- concept of "pure function" - always the same result for a
given set of parameters
- methods should have no "side effects"
- everything is a function
Lambda calculus
- mathematical formalism
- invented in 1932 by Alonzo Church
- turing complete - universal model of computation
- untyped and typed variety of the calculus
- making one "abstraction" == "declaring" a function λx.x
- everything is a function
Lambda calculus
Anjana Vakil, EuroPython Conference, July 2017
Core functional concepts
Currying in SCALA
def add(x:Int): Int=>Int = (y) => x + y
Add function:
def add(x:Int): Int=>Int = (y) => x + y
Curried function (full syntax):
def add(x:Int)(y:Int):Int = x + y
Curried function (short syntax):
add(6)(5)
val add6 = add(6)
add6(5)
val add6 = add(6)_
add6(5)
Currying in SCALA
def calculateMean(businessCustomersBasketVal: Int*)
(homeCustomersBasketVal: Int*): Float
Common usages:
or for error handling:
calculateMean(1,2,7,6,5)(1,2)
def registerCustomer (successAction: User => Unit)
(homeCustomersBasketVal:() => Unit): Float
EXERCISE 2
Create a curried func
$> brew install scala
Create a curried function which adds two arguments to each other
Tail recursion
- Function contains ONLY A SINGLE
recursive call and it is the last statement
to be executed
- Tail recursion can be replaced
by iteration to remove recursion
from the solution
Tail recursion
def factorial(x:Long):Long = if (x <= 1) 1
else x * factorial(x - 1)
factorial(100000L) //100 000
Exception in thread "main" java.lang.StackOverflowError
Recursion:
6 * 5 * 4 * 3 * 2 * 1
Tail recursion
def factorialTail(number:Long):Long = {
def factorialWithAcc (acc:Long, x:Long):Long =
if (x <= 1) acc
else factorialWithAcc(acc * number , number -1)
factorialWithAcc( 1, number)
}
factorialTail(100000L) //100 000
Recursion:
1 * 2 * 3 * 4 * 5 * 6
Tail recursion
Automatically transformed into iteration:
CHURCH NUMERALS
Representing numerals, operators & data in the lambda calculus
object ChurchNumerals {
type Succ[Z] = Z => Z
type ChNum[Z] = Succ[Z] => Z => Z
def zero[Z]: ChNum[Z] =
(_: Succ[Z]) => (z: Z) => z
def succ[Z] (num: ChNum[Z]): ChNum[Z] =
(s: Succ[Z]) => (z: Z) => s( num(s)(z) )
// a couple of church constants
def one[Z] : ChNum[Z] = succ(zero)
def two[Z] : ChNum[Z] = succ(one)
// the addition function
def add[Z] (a: ChNum[Z]) (b: ChNum[Z]) =
(s: Succ[Z]) => (z: Z) => a(s)( b(s)(z) )
def four[Z] : ChNum[Z] = add(two)(two)
// test
def church_to_int (num: ChNum[Int]): Int =
num((x: Int) => x + 1)(0)
def fourInt: Int = church_to_int(four)
def main(args: Array[String]): Unit = {
println(s"2 + 2 = ${fourInt}")
}
}
Lists
SCALA
systematically
distinguishes between
mutable and immutable
collections
MUTABLE ≠ IMMUTABLE
Lists
Lists
Array Buffers
List Buffers
StringBuilders
Linked Lists
Double Linked Lists
Mutable Lists
Queues
Array Sequences
Stacks
Array Stacks
Hash Tables
Weak Hash Maps
Concurrent Maps
Mutable Bitsets
Lists
// Create a Scala List in the Lisp style
val list = 1 :: 2 :: 3 :: Nil
// Create a Scala List in the Java style
val list2 = List(1,2,3)
val list3 = List[Number](1,2,3)
// Create a Scala List with the ‘range’ method
val list4 = List.range(1, 10) // List(1, 2, 3, 4, 5, 6, 7, 8, 9)
val list5 = List.range(0, 10, 2) // List(0, 2, 4, 6, 8)
// Create a Scala List with the List class ‘fill’ method
val x = List.fill(3)("foo") // List(foo, foo, foo)
Conversion from Java to SCALA collections
import collection.JavaConverters._
List(1,2,3).asJava // Java List
List(1,2,3).asJavaCollection // Java collection
Traits
- like Java 8 interfaces (Java 7 could not have interface implementation)
- abstract classes vs traits
- traits cannot have constructor parameters
Traits
class Ball {
def props(): List[String] = List()
override def toString() = "It's a" + props.mkString(" ", ", ", " ") + "ball"
}
trait Red extends Ball {
override def props() = super.props ::: List("red")
}
trait Shiny extends Ball {
override def props() = super.props ::: List("shiny")
}
// hint: traits are called from right to left
// that is Red and then Shiny
val myBall = new Ball with Shiny with Red
println(myBall) // It's a shiny, red ball
EXERCISE 3
Trait for pretty print
Create a trait which changes behaviour of List’s toString() method
EXERCISE 3
Solution
trait ListPrettyPrint[ T] extends mutable.MutableList[ T] {
override def toString() : String = {
this.mkString("[", ", elem: ", "]")
}
}
val stringList = (new mutable.MutableList[ String] with
ListPrettyPrint[ String]
+= "cat" += "dog" += "tiger")
println(stringList)
Apply and unapply functions
Apply - when you treat your object like a function, apply is the method
that is called
obj(a, b, c) is equivalent to obj.apply(a, b, c)
- one apply()’s args need to match constructor
object User {
def apply(name: String): User = new User(name)
}
Apply and unapply functions
Unapply - is used in Scala's pattern matching mechanism and its most
common use I've seen is in Extractor Objects
object User() {
def unapply(arg: User): Option[( String, String)] = {
Option.apply(("a", "b"))
}
}
Case classes
// Has properties id & msg
class Message(p_id:String, p_msg:String) {
val id = p_id
val msg = p_msg
}
// Has properties id & msg
class Message2(val id:String,val msg:String)
// Has properties id & msg
case class Message3(id:String, msg:String)
// Getter and setter methods (java) - getId(), setId() etc.
// Has properties id & msg
class Message4(@BeanProperty val id:String, @BeanProperty val
msg:String)
Case classes
// custom constructors
case class Message5(@BeanProperty val id:String,
@BeanProperty val msg:String) {
def this() = this(null, null)
def this(msg:String) = this(null, msg)
}
SCALA
SWITCH
Pattern matching
checking value against a pattern
procedural/functional - result can be returned
val random: Int = Random.nextInt(10)
val numberString = random match {
case 0 => "zero"
case 1 => "one"
case 2 => "two"
case _ => "many"
}
Pattern matching on type/case classes
abstract class Notification
case class Email(sender: String, title: String, body: String)
extends Notification
case class SMS(message: String) extends Notification
notification match {
case Email(sender, title, body_) =>
print(s"You got an email from $sender with title: $title")
case SMS(message) =>
print(s"You got an SMS! Message: $message")
}
Pattern matching on multiple types
abstract class Notification
case class Email(sender: String, title: String, body: String)
extends Notification
case class SMS(message: String) extends Notification
notification match {
case (Email(sender, title, body_) | SMS(message)) =>
print(s"You got a message” )
}
Safe pattern matching
object Foo {
def unapply(x : Int) : Option[String] =
if(x == 0) Some("This value is zero") else None
}
val myInt = 1
myInt match {
case Foo(str) => println(str)
}
Safe pattern matching
val myInt = 1
myInt match {
case Foo(str) => println(str)
case _ => println("other: _")
}
results in:
PATTERN MATCHING
vs
SWITCH
Pattern matching
STRING comparison
regex pattern search
Object vs Object comparison
- performance
- conciseness
(brevity of code)
DATA STREAM
Analyze data and look
for patterns
Pattern matching
Pattern matching
Recently languages are borrowing concepts from newer breed of
functional languages. Type inference and pattern matching I am
guessing goes back to ML. Eventually people will come to expect these
features too. Given that Lisp came out in 1958 and ML in 1973, it seems
to take decades for good ideas to catch on. For those cold decades,
these languages were probably considered heretical or worse “not
serious.”
EXERCISE 4
Pattern match emails
From a given messages list (mobile + email), select sucessive email
messages from the same person [i.e. ignoring domain names]
val messageList = List(
Message("tom@gmail.com" ,"Message text 1" ),
Message("7742394590","Message text 2" ),
Message("8326192398","Message text 3" ),
Message("lisa@gmail.com" ,"Message text 4" ),
Message("lisa@yahoo.com" ,"Message text 5" ),
Message("harry@gmail.com" ,"Message text 6" )
)
EXERCISE 4
Pattern match emailscase class Message(id:String, msg:String)
object Message{
def apply(id:String, msg:String) = new Message(id,msg)
def unapply(m:Message) :Option[(String,String)] = {
if (m == null) None
else Some(m.id, m.msg)
}
}
object EmailAddress {
def apply(uname: String, dname: String) = uname + "@" + dname
def unapply(str: String): Option[(String, String)] = {
val parts = str split "@"
if (parts.length == 2) Some(parts(0), parts(1)) else None
}
}
EXERCISE 4
Pattern match emails
def testMessagePattern (msgList:List[Message]):String = {
msgList match {
case Nil => "Not found"
case Message(EmailAddress(u1,d1),_) :: Message(EmailAddress(u2,d2),_) :: _
if u1 == u2 => u1 + " got two successive emails"
case h::t => testMessagePattern(t)
}
}
Pattern matching
By default, pattern matching does not work with regular
classes.
Use case classes or implement:
apply()/unapply() methods
Sealed classes
Higher order functions
- Functional languages treat functions as first-class values
- Function can be passed as a parameter and returned as a result
- Function type :
type A => B is the type of a function that takes an argument of type
A and returns a result of type B (i.e. lambda/closure)
-
Lazy evaluation
- Scala uses strict evaluation by default, but allows lazy evaluation
- Some languages use lazy evaluation as default - Haskell
- Lazy == “non strict”, “deferred execution”
Definition of lazy value:
lazy val x = 2 + 2
Lazy evaluation
1 less than 30?
1 more than 20?
25 less than 30?
25 more than 20?
25
40 less than 30?
5 less than 30?
5 more than 20?
23 less than 30?
23 more than 20?
23
// (20, 30)
def lessThan30(i: Int): Boolean = {
println(s"n$i less than 30?" )
i < 30
}
def moreThan20(i: Int): Boolean = {
println(s"$i more than 20?" )
i > 20
}
val a = List(1, 25, 40, 5, 23)
val q0 = a.withFilter(lessThan30)
val q1 = q0.withFilter(moreThan20)
for (r <- q1) println(s"$r")
withFilter() - non strict
Lazy evaluation
1 less than 30?
25 less than 30?
40 less than 30?
5 less than 30?
23 less than 30?
1 more than 20?
25 more than 20?
5 more than 20?
23 more than 20?
25
23
// (20, 30)
def lessThan30(i: Int): Boolean = {
println(s"n$i less than 30?" )
i < 30
}
def moreThan20(i: Int): Boolean = {
println(s"$i more than 20?" )
i > 20
}
val a = List(1, 25, 40, 5, 23)
val q0 = a.filter(lessThan30)
val q1 = q0.filter(moreThan20)
for (r <- q1) println(s"$r")
filter() - strict eval
Cache using lazy evaluation
- If you don’t use cache - the cost is 0 - value will never get evalueted
- If you use cache one or multiple times, the cost is always 1
- You can make a function lazy by assigning it to a lazy val !
- You can use lazy for network calls etc.
def foo(x: Int => Expensive) = {
lazy val cache = x
/* do lots of stuff with cache */
}
Unified type system
- Java makes a sharp distinction between primitive types (e.g. int
and boolean) and reference types (any class).
- In Scala, all types inherit from a top-level class Any, whose
immediate children are AnyVal (value types, such as Int and
Boolean) and AnyRef (reference types, as in Java)
- distinction between primitive types and boxed types (e.g. int vs.
Integer) is not present in Scala
- Scala 2.10 allows for new value types to be defined by the user
Unified type system
Value classes
class Foo(val name: String) extends AnyVal {
def print = println(name)
}
Value class
- Scala allows user-defined value classes that extend AnyVal
- Value classes in Scala do not allocate runtime objects
- Performance optimization
- Single, public val parameter that is the underlying runtime
representation
- A value class can define defs, but no vals, vars, or nested traits
classes or objects.
Value classes
val foo = new Foo("sample value" )
foo.print
- Now one can use newly defined methods
Nullability
- SCALA has no built-in support for null-safe types (Int?, Double? etc.)
- Option[T]
val numberOption = List(1,2,3,4).headOption
if (numberOption.isDefined) {
println(numberOption.get)
}
val number = numberOption.getOrElse(-1)
Nullability
- NOT SUPPORTED
val connSocketOption = List(connSocket).headOption
connSocketOption?.removeDevice() // NOT SUPPORTED :(
Dependencies definition
libraryDependencies ++=
{
val slickVersion = "3.2.1"
val postgresVersion = "42.2.1"
Seq(
"javax.inject" % "javax.inject" % "1",
"com.typesafe" % "config" % "1.3.1",
"org.postgresql" % "postgresql" % postgresVersion,
"com.typesafe.slick" %% "slick" % slickVersion,
//--- Testing
"org.springframework.boot" % "spring-boot-starter-test" % springBootVersion % Test,
"org.scalatest" %% "scalatest" % "3.0.1" % Test
)
}
Dependencies definition
- + usual maven/gradle syntax
"com.typesafe" % "config" % "1.3.1"
compile “com.typesafe:config:1.3.1”
- ++ adds scala version to the dependency
"com.typesafe.slick" %% "slick" % “3.2.1”
Companion objects
- Accompany classes
- Store constant values
- can access methods and fields that are private in the class/trait
-
class Foo() {
def getVersion = "1.2.1"
object c {
val TAG = "[PROCESSING]"
}
}
class ExtString(var str: String) {
var extraData: String = ""
override def toString: String = str + extraData
}
object ExtString {
def apply(base:String) : ExtString = new ExtString(base)
def apply(base:String, extras: String) : ExtString = {
new ExtString(base)
}
}
Infinite data structures
- lazy by default, like Haskell, laziness makes it easy to support
infinite data structures
- Scala is not lazy by default. If it was, we could define Fibonacci as:
fibonacci_sequence = for (i <- 0 to infinity) yield fib(i)
fibonacci_sequence.take(10)
Infinite data structures
- odd numbers:
def from(n: Int): Stream[Int] = Stream.cons(n, from(n+1))
lazy val ints = from(0)
lazy val odds = ints.filter(_ % 2 == 1)
odds.take(10).print
Type classes
- a type system construct that supports ad hoc polymorphism
object Math {
trait NumberLike[T] {
def plus(x: T, y: T): T
def divide(x: T, y: Int): T
def minus(x: T, y: T): T
}
object NumberLike {
implicit object NumberLikeDouble extends NumberLike[Double] {
def plus(x: Double, y: Double): Double = x + y
def divide(x: Double, y: Int): Double = x / y
def minus(x: Double, y: Double): Double = x - y
}
implicit object NumberLikeInt extends NumberLike[Int] {
def plus(x: Int, y: Int): Int = x + y
def divide(x: Int, y: Int): Int = x / y
def minus(x: Int, y: Int): Int = x - y
}
}
}
More info
Futures & Promises
- Define execution context
import ExecutionContext.Implicits.global
import scala.concurrent.Future
import scala.concurrent.blocking
Future {
blocking {
myLock.lock()
// so sth
}
}
SCALAZ
Scalaz is a Scala library for functional programming.
It provides purely functional data structures to complement those from
the Scala standard library. It defines a set of foundational type classes
(e.g. Functor, Monad) and corresponding instances for a large number of
data structures.
Functor, Monad
SCALA JS
Spark
- Source
- open-source cluster-computing framework. Originally developed at
the University of California
- mainframe computing
- written in SCALA
SCALA - AKKA agents
- Implement the REACTIVE MANIFESTO
- Binary/fast communication as default
- Easy to implement
SCALA - AKKA agents
SCALA - AKKA agents
val helloGreeter: ActorRef =
system.actorOf(Greeter.props( "Hello", printer), "helloGreeter" )
printerActor ! Greeting(greeting) //send a message
SLICK
Query
SLICK
Insert
Books
Books
Twitter & SCALA
- Scala twitter util
- bunch of idiomatic, small, general purpose tools.
- Time, collections,
- source
Links / References
- Scala & Scala JS;
- Oracle developers - Scala course - link
- Twitter Scala School - link
- Scala lang overview - link, Scala cheatsheet - link
- Why SCALA - link - interview with Odersky
- Steps in Scala - link (Loverdo, Christos 2010)
- Lightbend - introduction to Scala course - link
- Beyond Java - link
- Kotlin vs Scala - link, link, link
- Java criticism - link
- Can Java be used for functional programming? - link
- Europython - Lambda functions - link
- Functional programming - link
- Functional programming in JavaScript - link
- Mostly Adequate Guide to functional programming - link
- Programming and Problem Solving Using Scala - link
- Tail recursion in scala - link
Links / References
- Alexander Alvina,Funtions are variables too, link
- Kotlin & Funtional programming - link
- Scala basics video - link
- Functional programming principles in Scala - link, link, link, link
- Understanding tail recursion - link, link
- Composing traits LEGO style - link
- List creation in SCALA - link
- SCALA collections overview - link
- apply/unapply function - link
- Scala exercises - link
- Differences between lazy and strict evaluation: link
- Guide to Type classes - link
- Scala from a functional perspective - link
- Scala tour - value classes - link, link
- Scala method scope visibility - link
- Functors in SCALA - link
- Functor & Monad - link
- Functor, applicative, monads - link
Additional
- Why SCALA & Kotlin? Is Java 8 a truly functional language?
READ
- Learning SCALAZ - READ
QUESTIONS?

Más contenido relacionado

La actualidad más candente

Big Data Day LA 2016/ Hadoop/ Spark/ Kafka track - Real-time Aggregations, Ap...
Big Data Day LA 2016/ Hadoop/ Spark/ Kafka track - Real-time Aggregations, Ap...Big Data Day LA 2016/ Hadoop/ Spark/ Kafka track - Real-time Aggregations, Ap...
Big Data Day LA 2016/ Hadoop/ Spark/ Kafka track - Real-time Aggregations, Ap...Data Con LA
 
Introduction to Spark SQL and Catalyst / Spark SQLおよびCalalystの紹介
Introduction to Spark SQL and Catalyst / Spark SQLおよびCalalystの紹介Introduction to Spark SQL and Catalyst / Spark SQLおよびCalalystの紹介
Introduction to Spark SQL and Catalyst / Spark SQLおよびCalalystの紹介scalaconfjp
 
Alternatives of JPA/Hibernate
Alternatives of JPA/HibernateAlternatives of JPA/Hibernate
Alternatives of JPA/HibernateSunghyouk Bae
 
Kotlin: Why Do You Care?
Kotlin: Why Do You Care?Kotlin: Why Do You Care?
Kotlin: Why Do You Care?intelliyole
 
From object oriented to functional domain modeling
From object oriented to functional domain modelingFrom object oriented to functional domain modeling
From object oriented to functional domain modelingCodemotion
 
2018 05-16 Evolving Technologies: React, Babel & Webpack
2018 05-16 Evolving Technologies: React, Babel & Webpack2018 05-16 Evolving Technologies: React, Babel & Webpack
2018 05-16 Evolving Technologies: React, Babel & WebpackCodifly
 
Intro to GraphQL on Android with Apollo DroidconNYC 2017
Intro to GraphQL on Android with Apollo DroidconNYC 2017Intro to GraphQL on Android with Apollo DroidconNYC 2017
Intro to GraphQL on Android with Apollo DroidconNYC 2017Mike Nakhimovich
 
The Evolution of Scala / Scala進化論
The Evolution of Scala / Scala進化論The Evolution of Scala / Scala進化論
The Evolution of Scala / Scala進化論scalaconfjp
 
Connect.Tech- Level Up Your Game With TravisCI
Connect.Tech- Level Up Your Game With TravisCIConnect.Tech- Level Up Your Game With TravisCI
Connect.Tech- Level Up Your Game With TravisCIstable|kernel
 
Starting with Scala : Frontier Developer's Meetup December 2010
Starting with Scala : Frontier Developer's Meetup December 2010Starting with Scala : Frontier Developer's Meetup December 2010
Starting with Scala : Frontier Developer's Meetup December 2010Derek Chen-Becker
 
JavaScript in 2016
JavaScript in 2016JavaScript in 2016
JavaScript in 2016Codemotion
 
Building a Unified Data Pipline in Spark / Apache Sparkを用いたBig Dataパイプラインの統一
Building a Unified Data Pipline in Spark / Apache Sparkを用いたBig Dataパイプラインの統一Building a Unified Data Pipline in Spark / Apache Sparkを用いたBig Dataパイプラインの統一
Building a Unified Data Pipline in Spark / Apache Sparkを用いたBig Dataパイプラインの統一scalaconfjp
 
Metaprogramming in Scala 2.10, Eugene Burmako,
Metaprogramming  in Scala 2.10, Eugene Burmako, Metaprogramming  in Scala 2.10, Eugene Burmako,
Metaprogramming in Scala 2.10, Eugene Burmako, Vasil Remeniuk
 
Stepping Up : A Brief Intro to Scala
Stepping Up : A Brief Intro to ScalaStepping Up : A Brief Intro to Scala
Stepping Up : A Brief Intro to ScalaDerek Chen-Becker
 

La actualidad más candente (20)

Big Data Day LA 2016/ Hadoop/ Spark/ Kafka track - Real-time Aggregations, Ap...
Big Data Day LA 2016/ Hadoop/ Spark/ Kafka track - Real-time Aggregations, Ap...Big Data Day LA 2016/ Hadoop/ Spark/ Kafka track - Real-time Aggregations, Ap...
Big Data Day LA 2016/ Hadoop/ Spark/ Kafka track - Real-time Aggregations, Ap...
 
Scala coated JVM
Scala coated JVMScala coated JVM
Scala coated JVM
 
Spring data requery
Spring data requerySpring data requery
Spring data requery
 
Introduction to Spark SQL and Catalyst / Spark SQLおよびCalalystの紹介
Introduction to Spark SQL and Catalyst / Spark SQLおよびCalalystの紹介Introduction to Spark SQL and Catalyst / Spark SQLおよびCalalystの紹介
Introduction to Spark SQL and Catalyst / Spark SQLおよびCalalystの紹介
 
Alternatives of JPA/Hibernate
Alternatives of JPA/HibernateAlternatives of JPA/Hibernate
Alternatives of JPA/Hibernate
 
Kotlin: Why Do You Care?
Kotlin: Why Do You Care?Kotlin: Why Do You Care?
Kotlin: Why Do You Care?
 
From object oriented to functional domain modeling
From object oriented to functional domain modelingFrom object oriented to functional domain modeling
From object oriented to functional domain modeling
 
2018 05-16 Evolving Technologies: React, Babel & Webpack
2018 05-16 Evolving Technologies: React, Babel & Webpack2018 05-16 Evolving Technologies: React, Babel & Webpack
2018 05-16 Evolving Technologies: React, Babel & Webpack
 
Intro to GraphQL on Android with Apollo DroidconNYC 2017
Intro to GraphQL on Android with Apollo DroidconNYC 2017Intro to GraphQL on Android with Apollo DroidconNYC 2017
Intro to GraphQL on Android with Apollo DroidconNYC 2017
 
The Evolution of Scala / Scala進化論
The Evolution of Scala / Scala進化論The Evolution of Scala / Scala進化論
The Evolution of Scala / Scala進化論
 
Kpi driven-java-development
Kpi driven-java-developmentKpi driven-java-development
Kpi driven-java-development
 
Connect.Tech- Level Up Your Game With TravisCI
Connect.Tech- Level Up Your Game With TravisCIConnect.Tech- Level Up Your Game With TravisCI
Connect.Tech- Level Up Your Game With TravisCI
 
Starting with Scala : Frontier Developer's Meetup December 2010
Starting with Scala : Frontier Developer's Meetup December 2010Starting with Scala : Frontier Developer's Meetup December 2010
Starting with Scala : Frontier Developer's Meetup December 2010
 
scala
scalascala
scala
 
Requery overview
Requery overviewRequery overview
Requery overview
 
JavaScript in 2016
JavaScript in 2016JavaScript in 2016
JavaScript in 2016
 
Building a Unified Data Pipline in Spark / Apache Sparkを用いたBig Dataパイプラインの統一
Building a Unified Data Pipline in Spark / Apache Sparkを用いたBig Dataパイプラインの統一Building a Unified Data Pipline in Spark / Apache Sparkを用いたBig Dataパイプラインの統一
Building a Unified Data Pipline in Spark / Apache Sparkを用いたBig Dataパイプラインの統一
 
Pragmatic sbt
Pragmatic sbtPragmatic sbt
Pragmatic sbt
 
Metaprogramming in Scala 2.10, Eugene Burmako,
Metaprogramming  in Scala 2.10, Eugene Burmako, Metaprogramming  in Scala 2.10, Eugene Burmako,
Metaprogramming in Scala 2.10, Eugene Burmako,
 
Stepping Up : A Brief Intro to Scala
Stepping Up : A Brief Intro to ScalaStepping Up : A Brief Intro to Scala
Stepping Up : A Brief Intro to Scala
 

Similar a SCALA - Functional domain

Intro to Spark and Spark SQL
Intro to Spark and Spark SQLIntro to Spark and Spark SQL
Intro to Spark and Spark SQLjeykottalam
 
Real world scala
Real world scalaReal world scala
Real world scalalunfu zhong
 
Kotlin Developer Starter in Android projects
Kotlin Developer Starter in Android projectsKotlin Developer Starter in Android projects
Kotlin Developer Starter in Android projectsBartosz Kosarzycki
 
Kotlin Developer Starter in Android - STX Next Lightning Talks - Feb 12, 2016
Kotlin Developer Starter in Android - STX Next Lightning Talks - Feb 12, 2016Kotlin Developer Starter in Android - STX Next Lightning Talks - Feb 12, 2016
Kotlin Developer Starter in Android - STX Next Lightning Talks - Feb 12, 2016STX Next
 
Spark SQL Deep Dive @ Melbourne Spark Meetup
Spark SQL Deep Dive @ Melbourne Spark MeetupSpark SQL Deep Dive @ Melbourne Spark Meetup
Spark SQL Deep Dive @ Melbourne Spark MeetupDatabricks
 
Alberto Paro - Hands on Scala.js
Alberto Paro - Hands on Scala.jsAlberto Paro - Hands on Scala.js
Alberto Paro - Hands on Scala.jsScala Italy
 
Scala Italy 2015 - Hands On ScalaJS
Scala Italy 2015 - Hands On ScalaJSScala Italy 2015 - Hands On ScalaJS
Scala Italy 2015 - Hands On ScalaJSAlberto Paro
 
Artigo 81 - spark_tutorial.pdf
Artigo 81 - spark_tutorial.pdfArtigo 81 - spark_tutorial.pdf
Artigo 81 - spark_tutorial.pdfWalmirCouto3
 
Art & music vs Google App Engine
Art & music vs Google App EngineArt & music vs Google App Engine
Art & music vs Google App Enginethomas alisi
 
Crossing the Bridge: Connecting Rails and your Front-end Framework
Crossing the Bridge: Connecting Rails and your Front-end FrameworkCrossing the Bridge: Connecting Rails and your Front-end Framework
Crossing the Bridge: Connecting Rails and your Front-end FrameworkDaniel Spector
 
HTML5 for the Silverlight Guy
HTML5 for the Silverlight GuyHTML5 for the Silverlight Guy
HTML5 for the Silverlight GuyDavid Padbury
 
Programming in Scala: Notes
Programming in Scala: NotesProgramming in Scala: Notes
Programming in Scala: NotesRoberto Casadei
 
Planning with Polyalgebra: Bringing Together Relational, Complex and Machine ...
Planning with Polyalgebra: Bringing Together Relational, Complex and Machine ...Planning with Polyalgebra: Bringing Together Relational, Complex and Machine ...
Planning with Polyalgebra: Bringing Together Relational, Complex and Machine ...Julian Hyde
 
ScalaTo July 2019 - No more struggles with Apache Spark workloads in production
ScalaTo July 2019 - No more struggles with Apache Spark workloads in productionScalaTo July 2019 - No more struggles with Apache Spark workloads in production
ScalaTo July 2019 - No more struggles with Apache Spark workloads in productionChetan Khatri
 
Behavior driven oop
Behavior driven oopBehavior driven oop
Behavior driven oopPiyush Verma
 

Similar a SCALA - Functional domain (20)

Intro to Spark and Spark SQL
Intro to Spark and Spark SQLIntro to Spark and Spark SQL
Intro to Spark and Spark SQL
 
Real world scala
Real world scalaReal world scala
Real world scala
 
Kotlin Developer Starter in Android projects
Kotlin Developer Starter in Android projectsKotlin Developer Starter in Android projects
Kotlin Developer Starter in Android projects
 
Kotlin Developer Starter in Android - STX Next Lightning Talks - Feb 12, 2016
Kotlin Developer Starter in Android - STX Next Lightning Talks - Feb 12, 2016Kotlin Developer Starter in Android - STX Next Lightning Talks - Feb 12, 2016
Kotlin Developer Starter in Android - STX Next Lightning Talks - Feb 12, 2016
 
Spark SQL Deep Dive @ Melbourne Spark Meetup
Spark SQL Deep Dive @ Melbourne Spark MeetupSpark SQL Deep Dive @ Melbourne Spark Meetup
Spark SQL Deep Dive @ Melbourne Spark Meetup
 
Alberto Paro - Hands on Scala.js
Alberto Paro - Hands on Scala.jsAlberto Paro - Hands on Scala.js
Alberto Paro - Hands on Scala.js
 
Scala Italy 2015 - Hands On ScalaJS
Scala Italy 2015 - Hands On ScalaJSScala Italy 2015 - Hands On ScalaJS
Scala Italy 2015 - Hands On ScalaJS
 
Lambdas puzzler - Peter Lawrey
Lambdas puzzler - Peter LawreyLambdas puzzler - Peter Lawrey
Lambdas puzzler - Peter Lawrey
 
Artigo 81 - spark_tutorial.pdf
Artigo 81 - spark_tutorial.pdfArtigo 81 - spark_tutorial.pdf
Artigo 81 - spark_tutorial.pdf
 
Art & music vs Google App Engine
Art & music vs Google App EngineArt & music vs Google App Engine
Art & music vs Google App Engine
 
Crossing the Bridge: Connecting Rails and your Front-end Framework
Crossing the Bridge: Connecting Rails and your Front-end FrameworkCrossing the Bridge: Connecting Rails and your Front-end Framework
Crossing the Bridge: Connecting Rails and your Front-end Framework
 
Alteryx SDK
Alteryx SDKAlteryx SDK
Alteryx SDK
 
HTML5 for the Silverlight Guy
HTML5 for the Silverlight GuyHTML5 for the Silverlight Guy
HTML5 for the Silverlight Guy
 
Programming in Scala: Notes
Programming in Scala: NotesProgramming in Scala: Notes
Programming in Scala: Notes
 
Refactoring
RefactoringRefactoring
Refactoring
 
Polyalgebra
PolyalgebraPolyalgebra
Polyalgebra
 
Planning with Polyalgebra: Bringing Together Relational, Complex and Machine ...
Planning with Polyalgebra: Bringing Together Relational, Complex and Machine ...Planning with Polyalgebra: Bringing Together Relational, Complex and Machine ...
Planning with Polyalgebra: Bringing Together Relational, Complex and Machine ...
 
ScalaTo July 2019 - No more struggles with Apache Spark workloads in production
ScalaTo July 2019 - No more struggles with Apache Spark workloads in productionScalaTo July 2019 - No more struggles with Apache Spark workloads in production
ScalaTo July 2019 - No more struggles with Apache Spark workloads in production
 
Behavior driven oop
Behavior driven oopBehavior driven oop
Behavior driven oop
 
Mist - Serverless proxy to Apache Spark
Mist - Serverless proxy to Apache SparkMist - Serverless proxy to Apache Spark
Mist - Serverless proxy to Apache Spark
 

Más de Bartosz Kosarzycki

Droidcon Online 2020 quick summary
Droidcon Online 2020 quick summaryDroidcon Online 2020 quick summary
Droidcon Online 2020 quick summaryBartosz Kosarzycki
 
Flutter overview - advantages & disadvantages for business
Flutter overview - advantages & disadvantages for businessFlutter overview - advantages & disadvantages for business
Flutter overview - advantages & disadvantages for businessBartosz Kosarzycki
 
Flutter CI & Device Farms for Flutter
Flutter CI & Device Farms for FlutterFlutter CI & Device Farms for Flutter
Flutter CI & Device Farms for FlutterBartosz Kosarzycki
 
Drone racing - beginner's guide
Drone racing - beginner's guideDrone racing - beginner's guide
Drone racing - beginner's guideBartosz Kosarzycki
 
Optimize apps for Chromebooks - Meet.Intive Oct, 2018
Optimize apps for Chromebooks - Meet.Intive Oct, 2018Optimize apps for Chromebooks - Meet.Intive Oct, 2018
Optimize apps for Chromebooks - Meet.Intive Oct, 2018Bartosz Kosarzycki
 
Android - Gradle build optimisation 3d83f31339d239abcc55f869e5f30348?s=47
Android - Gradle build optimisation  3d83f31339d239abcc55f869e5f30348?s=47Android - Gradle build optimisation  3d83f31339d239abcc55f869e5f30348?s=47
Android - Gradle build optimisation 3d83f31339d239abcc55f869e5f30348?s=47Bartosz Kosarzycki
 
Android things introduction - Development for IoT
Android things introduction - Development for IoTAndroid things introduction - Development for IoT
Android things introduction - Development for IoTBartosz Kosarzycki
 
Daggerate your code - Write your own annotation processor
Daggerate your code - Write your own annotation processorDaggerate your code - Write your own annotation processor
Daggerate your code - Write your own annotation processorBartosz Kosarzycki
 
Introduction to Flutter - truly crossplatform, amazingly fast
Introduction to Flutter - truly crossplatform, amazingly fastIntroduction to Flutter - truly crossplatform, amazingly fast
Introduction to Flutter - truly crossplatform, amazingly fastBartosz Kosarzycki
 
Git-flow workflow and pull-requests
Git-flow workflow and pull-requestsGit-flow workflow and pull-requests
Git-flow workflow and pull-requestsBartosz Kosarzycki
 
ADG Poznań - Kotlin for Android developers
ADG Poznań - Kotlin for Android developersADG Poznań - Kotlin for Android developers
ADG Poznań - Kotlin for Android developersBartosz Kosarzycki
 
Kotlin advanced - language reference for android developers
Kotlin advanced - language reference for android developersKotlin advanced - language reference for android developers
Kotlin advanced - language reference for android developersBartosz Kosarzycki
 

Más de Bartosz Kosarzycki (17)

Droidcon Summary 2021
Droidcon Summary 2021Droidcon Summary 2021
Droidcon Summary 2021
 
Droidcon Online 2020 quick summary
Droidcon Online 2020 quick summaryDroidcon Online 2020 quick summary
Droidcon Online 2020 quick summary
 
Provider vs BLoC vs Redux
Provider vs BLoC vs ReduxProvider vs BLoC vs Redux
Provider vs BLoC vs Redux
 
Animations in Flutter
Animations in FlutterAnimations in Flutter
Animations in Flutter
 
Flutter overview - advantages & disadvantages for business
Flutter overview - advantages & disadvantages for businessFlutter overview - advantages & disadvantages for business
Flutter overview - advantages & disadvantages for business
 
Flutter CI & Device Farms for Flutter
Flutter CI & Device Farms for FlutterFlutter CI & Device Farms for Flutter
Flutter CI & Device Farms for Flutter
 
Drone racing - beginner's guide
Drone racing - beginner's guideDrone racing - beginner's guide
Drone racing - beginner's guide
 
Optimize apps for Chromebooks - Meet.Intive Oct, 2018
Optimize apps for Chromebooks - Meet.Intive Oct, 2018Optimize apps for Chromebooks - Meet.Intive Oct, 2018
Optimize apps for Chromebooks - Meet.Intive Oct, 2018
 
Android - Gradle build optimisation 3d83f31339d239abcc55f869e5f30348?s=47
Android - Gradle build optimisation  3d83f31339d239abcc55f869e5f30348?s=47Android - Gradle build optimisation  3d83f31339d239abcc55f869e5f30348?s=47
Android - Gradle build optimisation 3d83f31339d239abcc55f869e5f30348?s=47
 
DroidCon Berlin 2018 summary
DroidCon Berlin 2018 summaryDroidCon Berlin 2018 summary
DroidCon Berlin 2018 summary
 
Android things introduction - Development for IoT
Android things introduction - Development for IoTAndroid things introduction - Development for IoT
Android things introduction - Development for IoT
 
Daggerate your code - Write your own annotation processor
Daggerate your code - Write your own annotation processorDaggerate your code - Write your own annotation processor
Daggerate your code - Write your own annotation processor
 
Android antipatterns
Android antipatternsAndroid antipatterns
Android antipatterns
 
Introduction to Flutter - truly crossplatform, amazingly fast
Introduction to Flutter - truly crossplatform, amazingly fastIntroduction to Flutter - truly crossplatform, amazingly fast
Introduction to Flutter - truly crossplatform, amazingly fast
 
Git-flow workflow and pull-requests
Git-flow workflow and pull-requestsGit-flow workflow and pull-requests
Git-flow workflow and pull-requests
 
ADG Poznań - Kotlin for Android developers
ADG Poznań - Kotlin for Android developersADG Poznań - Kotlin for Android developers
ADG Poznań - Kotlin for Android developers
 
Kotlin advanced - language reference for android developers
Kotlin advanced - language reference for android developersKotlin advanced - language reference for android developers
Kotlin advanced - language reference for android developers
 

Último

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
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park masabamasaba
 
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
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfkalichargn70th171
 
SHRMPro HRMS Software Solutions Presentation
SHRMPro HRMS Software Solutions PresentationSHRMPro HRMS Software Solutions Presentation
SHRMPro HRMS Software Solutions PresentationShrmpro
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
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
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdfPearlKirahMaeRagusta1
 
%in Durban+277-882-255-28 abortion pills for sale in Durban
%in Durban+277-882-255-28 abortion pills for sale in Durban%in Durban+277-882-255-28 abortion pills for sale in Durban
%in Durban+277-882-255-28 abortion pills for sale in Durbanmasabamasaba
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
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
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplatePresentation.STUDIO
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesVictorSzoltysek
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionOnePlan Solutions
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisamasabamasaba
 
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...masabamasaba
 
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
 
%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Hararemasabamasaba
 
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
 

Último (20)

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
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
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 🔝✔️✔️
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
 
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
 
SHRMPro HRMS Software Solutions Presentation
SHRMPro HRMS Software Solutions PresentationSHRMPro HRMS Software Solutions Presentation
SHRMPro HRMS Software Solutions Presentation
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
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 🔝✔️✔️
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 
%in Durban+277-882-255-28 abortion pills for sale in Durban
%in Durban+277-882-255-28 abortion pills for sale in Durban%in Durban+277-882-255-28 abortion pills for sale in Durban
%in Durban+277-882-255-28 abortion pills for sale in Durban
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
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...
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...
 
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 ...
 
%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare
 
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
 

SCALA - Functional domain

  • 2. Outline - SCALA introduction - SCALA compared to other JVM languages / Kotlin vs SCALA - Basic SCALA syntax - Build tools - gradle/SBT - Lambda calculus - Functional programming - Currying - Pattern matching - Lazy evaluation - Scalaz
  • 3. SCALA runs on: Recommended IDEs: Interactive playground: https://scastie.scala-lang.org
  • 4. TIOBE index (march 2018): Language index Java 1 C++ 3 JavaScript 8 Swift 12 Go 17 Dart 22 Scala 30 Kotlin 38 Bash 43
  • 5. Companies using SCALA Company Purpose Twitter throughout the company, own utils LinkedIn Scalatra microframework Airbnb Aerosolve - open source machine learning software Zalando Entire technology stack Walmart Canada Backend platform SoundCloud Finagle (micro services), Scalding and Spark (data processing) Google Firebase (parts), Nest Verizon Quiver (multi-graphs), utils, whole tech. stack Others: Siemens, Sony Pictures, Imageworks, Duolingo...
  • 6. History of SCALA - Designed by Martin Odersky (who worked on Java generics in J2SE 5.0, and Pizza - Java with Generics, function pointers, case-classes, pattern-matching) - Released in 2003 - In May Odersky launches Typesafe Inc. (now - Lightbend Inc.) which provides commercial support for Scala - Scala is one of the few languages developed in close collaboration with university society (technically “in the Academia”) - As of now - Scala 2.12.4, increased performance - SCALA = Java (OO) + Pizza + functional programming focus * OO - Object Oriented Language
  • 8. Road to functional programming - SCALA - Seamless integration of functional programming features into an otherwise object-oriented language - “scala” - name comes from the ability to scale along with the growing complexity of the project - concurrent - ready for multi-core, micro-service world
  • 9. Road to functional programming - SCALA Non-functional Functional
  • 10. Kotlin vs SCALA SCALA Kotlin Java interoperability Java code from Scala (100%) Scala code from Java (edge cases not supported) bidirectional, 100% Pattern matching yes, better yes Design designed in the Academia designed by a leading software/IDE company Operator overloading yes, better + operator looking functions yes Compilation slower faster Community bigger smaller (still relatively new) Backward compatibility no yes (up to this point)
  • 11. Kotlin vs SCALA Scala has the right features, but its most obvious deficiency is very slow compilation," said Dmitry Jemerov, JetBrains development lead
  • 12. Kotlin vs SCALA Kotlin is a Better Java - excellent tools - syntactic sugar - performance - compatibility - simple rather than formal SCALA is more powerful than Java - designed to do things Java cannot - pattern matching - monads - traits - full-blown closures etc.
  • 14. Classes and Objects class Car { def startEngine(): Unit = { engine.invokeIgnition() } def openDoor(): Unit = { } } object Car { def build(color: Color): Car = { new Car().withColor(color) } val RED = Color.fromHex(“#FF0000”) }
  • 15. Methods class Car { val engine = new Engine() def startEngine(): Unit = { engine.invokeIgnition(); } def stopEngine = engine.stop } - {} are optional - ; are optional - () are optional - return value is optional - ‘return’ keyword is optional - whole class body is a ‘constructor’ (functional domain/everything is a func) - multiple parameter lists [this will exaplained later] def multiply(x:Int)(y:Int): Int = x * y
  • 16. Method arguments add({ val res = 33 + 66 println(res) res }, 2) def multiply (elems: Int*): Int = { elems.foldLeft( 0)((accum, element) => accum * element) }
  • 17. Multiple classes in a file + inner classes class Graph { class Node { var connectedNodes: List[Node] = Nil } } class Tree
  • 19. Build systems for SCALA SBT - performance - SBT shell - “Scala build tool” GRADLE - possible - more configuration needed - gradle 4.6 Scala Plugin - link
  • 20. Build tools: Gradle - Install gradle (brew on macos/apt-get ubuntu) - Run initialization script - Import build.gradle into IntelliJ IDEA - Add “.idea” & “.gradle” to .gitignore Repository: link Branch: feature/gradle-build-tool $> gradle init --type scala-library $> ./gradlew clean build $> brew install gradle
  • 21. Build tools: Gradle Repository: link Branch: feature/gradle-build-tool class Application { def run(args: Array[String]): Unit = { println("Hello world!" ) } } object Application extends App { override def main(args: Array[String]): Unit = { new Application().run(args) } } Entry point
  • 22. Build tools: Gradle Repository: link Branch: feature/gradle-build-tool Build.gradle: plugins { // Apply the scala plugin to add support for Scala id 'scala' } dependencies { // Use Scala 2.11 in our library project compile 'org.scala-lang:scala-library:2.11.8' } repositories { jcenter() }
  • 23. EXERCISE 1 Create gradle project $> gradle init --type scala-library $> ./gradlew clean build$> brew install gradle
  • 24. Build tools: SBT - Install sbt (brew install sbt / Linux: link) - Check version: sbt sbtVersion [1.1.1] - run ‘scala new’ and name the project ‘cododajnia’ - Import build.sbt into IntelliJ IDEA - Add “.idea” to gitignore Repository: link Branch: feature/sbt-build-tool $> sbt new scala/hello-world.g8 $> cd cododajnia; sbt clean compile $> brew install sbt $> sbt sbtVersion
  • 25. Build tools: SBT Add “target/” & “project/target/” to .gitignore Repository: link Branch: feature/sbt-build-tool object Main extends App { println("Hello, World!") } Main object is added automatically: scalaVersion := "2.12.4" name := "hello-world" organization := "ch.epfl.scala" version := "1.0" libraryDependencies += "org.typelevel" %% "cats-core" % "1.0.1"
  • 26. EXERCISE 2 Create sbt project $> brew install sbt $> sbt new scala/hello-world.g8 $> cd cododajnia; sbt clean compile
  • 28. Functional programming - computation as the evaluation of mathematical functions - avoids mutable data, stateless - expressions/declarations instead of statements - originates from λ-calculus (lambda calculus) - concept of "pure function" - always the same result for a given set of parameters - methods should have no "side effects" - everything is a function
  • 29. Lambda calculus - mathematical formalism - invented in 1932 by Alonzo Church - turing complete - universal model of computation - untyped and typed variety of the calculus - making one "abstraction" == "declaring" a function λx.x - everything is a function
  • 30. Lambda calculus Anjana Vakil, EuroPython Conference, July 2017
  • 32. Currying in SCALA def add(x:Int): Int=>Int = (y) => x + y Add function: def add(x:Int): Int=>Int = (y) => x + y Curried function (full syntax): def add(x:Int)(y:Int):Int = x + y Curried function (short syntax): add(6)(5) val add6 = add(6) add6(5) val add6 = add(6)_ add6(5)
  • 33. Currying in SCALA def calculateMean(businessCustomersBasketVal: Int*) (homeCustomersBasketVal: Int*): Float Common usages: or for error handling: calculateMean(1,2,7,6,5)(1,2) def registerCustomer (successAction: User => Unit) (homeCustomersBasketVal:() => Unit): Float
  • 34. EXERCISE 2 Create a curried func $> brew install scala Create a curried function which adds two arguments to each other
  • 35. Tail recursion - Function contains ONLY A SINGLE recursive call and it is the last statement to be executed - Tail recursion can be replaced by iteration to remove recursion from the solution
  • 36. Tail recursion def factorial(x:Long):Long = if (x <= 1) 1 else x * factorial(x - 1) factorial(100000L) //100 000 Exception in thread "main" java.lang.StackOverflowError Recursion: 6 * 5 * 4 * 3 * 2 * 1
  • 37. Tail recursion def factorialTail(number:Long):Long = { def factorialWithAcc (acc:Long, x:Long):Long = if (x <= 1) acc else factorialWithAcc(acc * number , number -1) factorialWithAcc( 1, number) } factorialTail(100000L) //100 000 Recursion: 1 * 2 * 3 * 4 * 5 * 6
  • 39. CHURCH NUMERALS Representing numerals, operators & data in the lambda calculus
  • 40. object ChurchNumerals { type Succ[Z] = Z => Z type ChNum[Z] = Succ[Z] => Z => Z def zero[Z]: ChNum[Z] = (_: Succ[Z]) => (z: Z) => z def succ[Z] (num: ChNum[Z]): ChNum[Z] = (s: Succ[Z]) => (z: Z) => s( num(s)(z) ) // a couple of church constants def one[Z] : ChNum[Z] = succ(zero) def two[Z] : ChNum[Z] = succ(one) // the addition function def add[Z] (a: ChNum[Z]) (b: ChNum[Z]) = (s: Succ[Z]) => (z: Z) => a(s)( b(s)(z) ) def four[Z] : ChNum[Z] = add(two)(two) // test def church_to_int (num: ChNum[Int]): Int = num((x: Int) => x + 1)(0) def fourInt: Int = church_to_int(four) def main(args: Array[String]): Unit = { println(s"2 + 2 = ${fourInt}") } }
  • 41. Lists SCALA systematically distinguishes between mutable and immutable collections MUTABLE ≠ IMMUTABLE
  • 42. Lists
  • 43. Lists Array Buffers List Buffers StringBuilders Linked Lists Double Linked Lists Mutable Lists Queues Array Sequences Stacks Array Stacks Hash Tables Weak Hash Maps Concurrent Maps Mutable Bitsets
  • 44. Lists // Create a Scala List in the Lisp style val list = 1 :: 2 :: 3 :: Nil // Create a Scala List in the Java style val list2 = List(1,2,3) val list3 = List[Number](1,2,3) // Create a Scala List with the ‘range’ method val list4 = List.range(1, 10) // List(1, 2, 3, 4, 5, 6, 7, 8, 9) val list5 = List.range(0, 10, 2) // List(0, 2, 4, 6, 8) // Create a Scala List with the List class ‘fill’ method val x = List.fill(3)("foo") // List(foo, foo, foo)
  • 45. Conversion from Java to SCALA collections import collection.JavaConverters._ List(1,2,3).asJava // Java List List(1,2,3).asJavaCollection // Java collection
  • 46. Traits - like Java 8 interfaces (Java 7 could not have interface implementation) - abstract classes vs traits - traits cannot have constructor parameters
  • 47. Traits class Ball { def props(): List[String] = List() override def toString() = "It's a" + props.mkString(" ", ", ", " ") + "ball" } trait Red extends Ball { override def props() = super.props ::: List("red") } trait Shiny extends Ball { override def props() = super.props ::: List("shiny") } // hint: traits are called from right to left // that is Red and then Shiny val myBall = new Ball with Shiny with Red println(myBall) // It's a shiny, red ball
  • 48. EXERCISE 3 Trait for pretty print Create a trait which changes behaviour of List’s toString() method
  • 49. EXERCISE 3 Solution trait ListPrettyPrint[ T] extends mutable.MutableList[ T] { override def toString() : String = { this.mkString("[", ", elem: ", "]") } } val stringList = (new mutable.MutableList[ String] with ListPrettyPrint[ String] += "cat" += "dog" += "tiger") println(stringList)
  • 50. Apply and unapply functions Apply - when you treat your object like a function, apply is the method that is called obj(a, b, c) is equivalent to obj.apply(a, b, c) - one apply()’s args need to match constructor object User { def apply(name: String): User = new User(name) }
  • 51. Apply and unapply functions Unapply - is used in Scala's pattern matching mechanism and its most common use I've seen is in Extractor Objects object User() { def unapply(arg: User): Option[( String, String)] = { Option.apply(("a", "b")) } }
  • 52. Case classes // Has properties id & msg class Message(p_id:String, p_msg:String) { val id = p_id val msg = p_msg } // Has properties id & msg class Message2(val id:String,val msg:String) // Has properties id & msg case class Message3(id:String, msg:String) // Getter and setter methods (java) - getId(), setId() etc. // Has properties id & msg class Message4(@BeanProperty val id:String, @BeanProperty val msg:String)
  • 53. Case classes // custom constructors case class Message5(@BeanProperty val id:String, @BeanProperty val msg:String) { def this() = this(null, null) def this(msg:String) = this(null, msg) }
  • 55. Pattern matching checking value against a pattern procedural/functional - result can be returned val random: Int = Random.nextInt(10) val numberString = random match { case 0 => "zero" case 1 => "one" case 2 => "two" case _ => "many" }
  • 56. Pattern matching on type/case classes abstract class Notification case class Email(sender: String, title: String, body: String) extends Notification case class SMS(message: String) extends Notification notification match { case Email(sender, title, body_) => print(s"You got an email from $sender with title: $title") case SMS(message) => print(s"You got an SMS! Message: $message") }
  • 57. Pattern matching on multiple types abstract class Notification case class Email(sender: String, title: String, body: String) extends Notification case class SMS(message: String) extends Notification notification match { case (Email(sender, title, body_) | SMS(message)) => print(s"You got a message” ) }
  • 58. Safe pattern matching object Foo { def unapply(x : Int) : Option[String] = if(x == 0) Some("This value is zero") else None } val myInt = 1 myInt match { case Foo(str) => println(str) }
  • 59. Safe pattern matching val myInt = 1 myInt match { case Foo(str) => println(str) case _ => println("other: _") } results in:
  • 61. Pattern matching STRING comparison regex pattern search Object vs Object comparison - performance - conciseness (brevity of code)
  • 62. DATA STREAM Analyze data and look for patterns Pattern matching
  • 63. Pattern matching Recently languages are borrowing concepts from newer breed of functional languages. Type inference and pattern matching I am guessing goes back to ML. Eventually people will come to expect these features too. Given that Lisp came out in 1958 and ML in 1973, it seems to take decades for good ideas to catch on. For those cold decades, these languages were probably considered heretical or worse “not serious.”
  • 64. EXERCISE 4 Pattern match emails From a given messages list (mobile + email), select sucessive email messages from the same person [i.e. ignoring domain names] val messageList = List( Message("tom@gmail.com" ,"Message text 1" ), Message("7742394590","Message text 2" ), Message("8326192398","Message text 3" ), Message("lisa@gmail.com" ,"Message text 4" ), Message("lisa@yahoo.com" ,"Message text 5" ), Message("harry@gmail.com" ,"Message text 6" ) )
  • 65. EXERCISE 4 Pattern match emailscase class Message(id:String, msg:String) object Message{ def apply(id:String, msg:String) = new Message(id,msg) def unapply(m:Message) :Option[(String,String)] = { if (m == null) None else Some(m.id, m.msg) } } object EmailAddress { def apply(uname: String, dname: String) = uname + "@" + dname def unapply(str: String): Option[(String, String)] = { val parts = str split "@" if (parts.length == 2) Some(parts(0), parts(1)) else None } }
  • 66. EXERCISE 4 Pattern match emails def testMessagePattern (msgList:List[Message]):String = { msgList match { case Nil => "Not found" case Message(EmailAddress(u1,d1),_) :: Message(EmailAddress(u2,d2),_) :: _ if u1 == u2 => u1 + " got two successive emails" case h::t => testMessagePattern(t) } }
  • 67. Pattern matching By default, pattern matching does not work with regular classes. Use case classes or implement: apply()/unapply() methods
  • 69. Higher order functions - Functional languages treat functions as first-class values - Function can be passed as a parameter and returned as a result - Function type : type A => B is the type of a function that takes an argument of type A and returns a result of type B (i.e. lambda/closure) -
  • 70. Lazy evaluation - Scala uses strict evaluation by default, but allows lazy evaluation - Some languages use lazy evaluation as default - Haskell - Lazy == “non strict”, “deferred execution” Definition of lazy value: lazy val x = 2 + 2
  • 71. Lazy evaluation 1 less than 30? 1 more than 20? 25 less than 30? 25 more than 20? 25 40 less than 30? 5 less than 30? 5 more than 20? 23 less than 30? 23 more than 20? 23 // (20, 30) def lessThan30(i: Int): Boolean = { println(s"n$i less than 30?" ) i < 30 } def moreThan20(i: Int): Boolean = { println(s"$i more than 20?" ) i > 20 } val a = List(1, 25, 40, 5, 23) val q0 = a.withFilter(lessThan30) val q1 = q0.withFilter(moreThan20) for (r <- q1) println(s"$r") withFilter() - non strict
  • 72. Lazy evaluation 1 less than 30? 25 less than 30? 40 less than 30? 5 less than 30? 23 less than 30? 1 more than 20? 25 more than 20? 5 more than 20? 23 more than 20? 25 23 // (20, 30) def lessThan30(i: Int): Boolean = { println(s"n$i less than 30?" ) i < 30 } def moreThan20(i: Int): Boolean = { println(s"$i more than 20?" ) i > 20 } val a = List(1, 25, 40, 5, 23) val q0 = a.filter(lessThan30) val q1 = q0.filter(moreThan20) for (r <- q1) println(s"$r") filter() - strict eval
  • 73. Cache using lazy evaluation - If you don’t use cache - the cost is 0 - value will never get evalueted - If you use cache one or multiple times, the cost is always 1 - You can make a function lazy by assigning it to a lazy val ! - You can use lazy for network calls etc. def foo(x: Int => Expensive) = { lazy val cache = x /* do lots of stuff with cache */ }
  • 74. Unified type system - Java makes a sharp distinction between primitive types (e.g. int and boolean) and reference types (any class). - In Scala, all types inherit from a top-level class Any, whose immediate children are AnyVal (value types, such as Int and Boolean) and AnyRef (reference types, as in Java) - distinction between primitive types and boxed types (e.g. int vs. Integer) is not present in Scala - Scala 2.10 allows for new value types to be defined by the user
  • 76. Value classes class Foo(val name: String) extends AnyVal { def print = println(name) } Value class - Scala allows user-defined value classes that extend AnyVal - Value classes in Scala do not allocate runtime objects - Performance optimization - Single, public val parameter that is the underlying runtime representation - A value class can define defs, but no vals, vars, or nested traits classes or objects.
  • 77. Value classes val foo = new Foo("sample value" ) foo.print - Now one can use newly defined methods
  • 78. Nullability - SCALA has no built-in support for null-safe types (Int?, Double? etc.) - Option[T] val numberOption = List(1,2,3,4).headOption if (numberOption.isDefined) { println(numberOption.get) } val number = numberOption.getOrElse(-1)
  • 79. Nullability - NOT SUPPORTED val connSocketOption = List(connSocket).headOption connSocketOption?.removeDevice() // NOT SUPPORTED :(
  • 80. Dependencies definition libraryDependencies ++= { val slickVersion = "3.2.1" val postgresVersion = "42.2.1" Seq( "javax.inject" % "javax.inject" % "1", "com.typesafe" % "config" % "1.3.1", "org.postgresql" % "postgresql" % postgresVersion, "com.typesafe.slick" %% "slick" % slickVersion, //--- Testing "org.springframework.boot" % "spring-boot-starter-test" % springBootVersion % Test, "org.scalatest" %% "scalatest" % "3.0.1" % Test ) }
  • 81. Dependencies definition - + usual maven/gradle syntax "com.typesafe" % "config" % "1.3.1" compile “com.typesafe:config:1.3.1” - ++ adds scala version to the dependency "com.typesafe.slick" %% "slick" % “3.2.1”
  • 82. Companion objects - Accompany classes - Store constant values - can access methods and fields that are private in the class/trait - class Foo() { def getVersion = "1.2.1" object c { val TAG = "[PROCESSING]" } } class ExtString(var str: String) { var extraData: String = "" override def toString: String = str + extraData } object ExtString { def apply(base:String) : ExtString = new ExtString(base) def apply(base:String, extras: String) : ExtString = { new ExtString(base) } }
  • 83. Infinite data structures - lazy by default, like Haskell, laziness makes it easy to support infinite data structures - Scala is not lazy by default. If it was, we could define Fibonacci as: fibonacci_sequence = for (i <- 0 to infinity) yield fib(i) fibonacci_sequence.take(10)
  • 84. Infinite data structures - odd numbers: def from(n: Int): Stream[Int] = Stream.cons(n, from(n+1)) lazy val ints = from(0) lazy val odds = ints.filter(_ % 2 == 1) odds.take(10).print
  • 85. Type classes - a type system construct that supports ad hoc polymorphism object Math { trait NumberLike[T] { def plus(x: T, y: T): T def divide(x: T, y: Int): T def minus(x: T, y: T): T } object NumberLike { implicit object NumberLikeDouble extends NumberLike[Double] { def plus(x: Double, y: Double): Double = x + y def divide(x: Double, y: Int): Double = x / y def minus(x: Double, y: Double): Double = x - y } implicit object NumberLikeInt extends NumberLike[Int] { def plus(x: Int, y: Int): Int = x + y def divide(x: Int, y: Int): Int = x / y def minus(x: Int, y: Int): Int = x - y } } } More info
  • 86. Futures & Promises - Define execution context import ExecutionContext.Implicits.global import scala.concurrent.Future import scala.concurrent.blocking Future { blocking { myLock.lock() // so sth } }
  • 87. SCALAZ Scalaz is a Scala library for functional programming. It provides purely functional data structures to complement those from the Scala standard library. It defines a set of foundational type classes (e.g. Functor, Monad) and corresponding instances for a large number of data structures.
  • 90. Spark - Source - open-source cluster-computing framework. Originally developed at the University of California - mainframe computing - written in SCALA
  • 91. SCALA - AKKA agents - Implement the REACTIVE MANIFESTO - Binary/fast communication as default - Easy to implement
  • 92. SCALA - AKKA agents
  • 93. SCALA - AKKA agents val helloGreeter: ActorRef = system.actorOf(Greeter.props( "Hello", printer), "helloGreeter" ) printerActor ! Greeting(greeting) //send a message
  • 96. Books
  • 97. Books
  • 98. Twitter & SCALA - Scala twitter util - bunch of idiomatic, small, general purpose tools. - Time, collections, - source
  • 99. Links / References - Scala & Scala JS; - Oracle developers - Scala course - link - Twitter Scala School - link - Scala lang overview - link, Scala cheatsheet - link - Why SCALA - link - interview with Odersky - Steps in Scala - link (Loverdo, Christos 2010) - Lightbend - introduction to Scala course - link - Beyond Java - link - Kotlin vs Scala - link, link, link - Java criticism - link - Can Java be used for functional programming? - link - Europython - Lambda functions - link - Functional programming - link - Functional programming in JavaScript - link - Mostly Adequate Guide to functional programming - link - Programming and Problem Solving Using Scala - link - Tail recursion in scala - link
  • 100. Links / References - Alexander Alvina,Funtions are variables too, link - Kotlin & Funtional programming - link - Scala basics video - link - Functional programming principles in Scala - link, link, link, link - Understanding tail recursion - link, link - Composing traits LEGO style - link - List creation in SCALA - link - SCALA collections overview - link - apply/unapply function - link - Scala exercises - link - Differences between lazy and strict evaluation: link - Guide to Type classes - link - Scala from a functional perspective - link - Scala tour - value classes - link, link - Scala method scope visibility - link - Functors in SCALA - link - Functor & Monad - link - Functor, applicative, monads - link
  • 101. Additional - Why SCALA & Kotlin? Is Java 8 a truly functional language? READ - Learning SCALAZ - READ
  • 102.