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
42
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
スタートアップの急成長を支えるプラットフォームエンジニアリングと組織戦略
sutochin26
1
5.8k
プロダクト志向ってなんなんだろうね
righttouch
PRO
0
190
AIと”コードの評価関数”を共有する / Share the "code evaluation function" with AI
euglena1215
1
170
新メンバーも今日から大活躍!SREが支えるスケールし続ける組織のオンボーディング
honmarkhunt
5
7.4k
Webの外へ飛び出せ NativePHPが切り拓くPHPの未来
takuyakatsusa
2
550
Discover Metal 4
rei315
2
140
Agentic Coding: The Future of Software Development with Agents
mitsuhiko
0
100
PipeCDのプラグイン化で目指すところ
warashi
1
280
第9回 情シス転職ミートアップ 株式会社IVRy(アイブリー)の紹介
ivry_presentationmaterials
1
320
Railsアプリケーションと パフォーマンスチューニング ー 秒間5万リクエストの モバイルオーダーシステムを支える事例 ー Rubyセミナー 大阪
falcon8823
5
1.1k
XP, Testing and ninja testing
m_seki
3
250
脱Riverpod?fqueryで考える、TanStack Queryライクなアーキテクチャの可能性
ostk0069
0
150
Featured
See All Featured
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
233
17k
The Cult of Friendly URLs
andyhume
79
6.5k
Adopting Sorbet at Scale
ufuk
77
9.5k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
53
2.9k
Producing Creativity
orderedlist
PRO
346
40k
How to Think Like a Performance Engineer
csswizardry
25
1.7k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
26
2.9k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
10
950
The MySQL Ecosystem @ GitHub 2015
samlambert
251
13k
YesSQL, Process and Tooling at Scale
rocio
173
14k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
PRO
181
54k
The Language of Interfaces
destraynor
158
25k
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! !