Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Programación Funcional con Scala
Search
Rebecca
September 25, 2013
Programming
0
44
Programación Funcional con Scala
Una charla por Quito Lambda
Rebecca
September 25, 2013
Tweet
Share
More Decks by Rebecca
See All by Rebecca
A Tale of Two Feature Flags
rsliter
0
360
Other Decks in Programming
See All in Programming
250830 IaCの選定~AWS SAMのLambdaをECSに乗り換えたときの備忘録~
east_takumi
0
400
プロポーザル駆動学習 / Proposal-Driven Learning
mackey0225
2
1.3k
複雑なドメインに挑む.pdf
yukisakai1225
5
1.2k
AWS発のAIエディタKiroを使ってみた
iriikeita
1
190
さようなら Date。 ようこそTemporal! 3年間先行利用して得られた知見の共有
8beeeaaat
3
1.5k
チームのテスト力を鍛える
goyoki
3
930
為你自己學 Python - 冷知識篇
eddie
1
350
プロパティベーステストによるUIテスト: LLMによるプロパティ定義生成でエッジケースを捉える
tetta_pdnt
0
4.3k
そのAPI、誰のため? Androidライブラリ設計における利用者目線の実践テクニック
mkeeda
2
2.8k
楽して成果を出すためのセルフリソース管理
clipnote
0
190
請來的 AI Agent 同事們在寫程式時,怎麼用 pytest 去除各種幻想與盲點
keitheis
0
130
RDoc meets YARD
okuramasafumi
4
170
Featured
See All Featured
XXLCSS - How to scale CSS and keep your sanity
sugarenia
248
1.3M
How to Think Like a Performance Engineer
csswizardry
26
1.9k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
29
2.9k
The Invisible Side of Design
smashingmag
301
51k
The Cult of Friendly URLs
andyhume
79
6.6k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
48
9.7k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
44
2.5k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
162
15k
Building Better People: How to give real-time feedback that sticks.
wjessup
368
19k
Navigating Team Friction
lara
189
15k
Typedesign – Prime Four
hannesfritz
42
2.8k
GraphQLの誤解/rethinking-graphql
sonatard
72
11k
Transcript
PF! Rebecca Sliter, ThoughtWorks @rebeccasliter! con! Scala!
utiliza el JVM!
static-typed! utiliza el JVM!
static-typed! orientado a objetos! utiliza el JVM!
static-typed! orientado a objetos?! utiliza el JVM!
static-typed! orientado a objetos! utiliza el JVM!
static-typed! funcional! orientado a objetos! utiliza el JVM!
static-typed! funcional! orientado a objetos! objeto-funcional! utiliza el JVM!
funcional! Qué hace! a este lenguaje?!
Funciones de orden superior! Funciones que tienen otra función como
parametro!
Funciones de orden superior! Funciones que tienen otra función como
parametro! Funciones que retornan una función!
Funciones de orden superior! object Almuerzo {! "def main(args: Array[String])
{! " "println( apply( postre, 50) )! "}! ! "def apply(f: Int => String, v: Int) = f(v)! ! "def postre(x: Int) = “Comi “ + x.toString() + “ frutas.”! }! !
Funciones de orden superior! Comi 50 frutas.! object Almuerzo {!
"def main(args: Array[String]) {! " "println( apply( postre, 50) )! "}! ! "def apply(f: Int => String, v: Int) = f(v)! ! "def postre(x: Int) = “Comi “ + x.toString() + “ frutas.”! }! !
Evaluación estricta! scala> val a = b + 1; val
b = 2;! a: Int = 1! b: Int = 2! ! !
Evaluación estricta! perezosa! scala> lazy val a = b +
1; lazy val b = 2;! a: Int = <lazy>! b: Int = <lazy>! ! scala> a! res1: Int = 3! ! scala> b! res1: Int = 2! ! !
Currying! scala> def add(a: Int)(b: Int) = a + b!
add: (a: Int)(b: Int)Int! !
Currying! scala> def add(a: Int)(b: Int) = a + b!
add: (a: Int)(b: Int)Int! ! scala> add(5)(6)! res1: Int = 11! !
Currying! scala> def add(a: Int)(b: Int) = a + b!
add: (a: Int)(b: Int)Int! ! scala> add(5)(6)! res1: Int = 11! ! scala> val addTen = add(10)_! addTen: Int => Int = <function>! !
Currying! scala> def add(a: Int)(b: Int) = a + b!
add: (a: Int)(b: Int)Int! ! scala> add(5)(6)! res1: Int = 11! ! scala> val addTen = add(10)_! addTen: Int => Int = <function>! ! scala> addTen(6)! res2: Int = 16!
Combinadores Funcionales! scala> val numeros = List(1,2,3)! numeros: List[Int] =
List(1, 2, 3)! ! scala> numeros.map((i: Int) => i * 3))! res1: List[Int] = List(3, 6, 9)! ! !
Combinadores Funcionales! scala> val numeros = List(1,2,3)! numeros: List[Int] =
List(1, 2, 3)! ! scala> numeros.partition(_ +1 == 3))! res1: (List[Int], List[Int]) = (List(2),List(1, 3))! ! !
Tipado estático!
Tipado estático! *la inferencia de tipos!
Tipado estático! *la inferencia de tipos! scala> val x :
Int = 1 + 2! x: Int = 3! ! ! !
Tipado estático! *la inferencia de tipos! scala> val x :
Int = 1 + 2! x: Int = 3! ! ! ! scala> val x = 1 + 2! x: Int = 3! ! ! !
Cuando la inferencia no funciona…! scala> def factorial(n: Int) =
{! | if (n == 0) 1! | else n * factorial(n – 1)! | }! ! ! <console>:1: error: recursive method factorial needs result type! else n * factorial(n – 1)! " " " " ^! ! !
Cuando la inferencia no funciona…! scala> def factorial(n: Int) =
{! | if (n == 0) 1! | else n * factorial(n – 1)! | }! ! scala> def factorial(n: Int) : Int = {! | if (n == 0) 1! | else n * factorial(n – 1)! | }! Factorial: (n: Int)Int! ! !
orientado a objetos! funcional! objeto-funcional!
orientado a objetos! objeto-funcional! funcional!
orientado a objetos! Qué hace! a este lenguaje?!
Traits! Colecciones de fields y comportamientos que pueden extend o
mixin a sus clases. !
trait Pelicula {! "val tipo: String ! } ! !
Traits!
trait Pelicula {! "val tipo: String ! } ! !
class Comedia extends Pelicula {! "val tipo = “comedia”! }! ! Traits!
trait Pelicula {! "val tipo: String! } ! ! class
Comedia extends Pelicula with Tiempo {! "val tipo = “comedia”! "val longitud = 90! }! ! Traits! trait Tiempo {! "val longitud: Int! } ! !
Modules!
Recursos! Scala docs: docs.scala-lang.org! Simply Scala: simplyscala.com! Scala School: twitter.github.io/scala_school!
$ sbt console! !