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
38
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
230
Other Decks in Programming
See All in Programming
CA.swift19 恋するAIアプリ開発の裏側
oskmr
0
380
障害対応を起点としたもっといい開発と運用のサイクル作りのためにできること / Hatena Enginner Seminar #29
polamjag
0
400
R言語の環境構築と基礎 Tokyo.R 112
bob3bob3
0
280
効率化に挑戦してみたらモバイル開発が少し快適になった話
ryunakayama
0
140
CREってこういうこと? 体験入社 - 提案資料 - / what-is-cre-trial-employment
shinden
1
550
StoreKit2によるiOSのアプリ内課金のリニューアル
kangnux
0
130
The Cutting Edge Of Versioning (LambdaConf 2024)
chriskrycho
0
130
AWS CDKコントリビュートTIPS / aws-cdk-contribution-tips
gotok365
4
410
Micro Frontends for Java Microservices - Utah JUG 2024
mraible
PRO
1
110
スキーマ駆動開発による品質とスピードの両立 - 私達は何故、スキーマを書くのか
kentaroutakeda
0
180
Let's learn code review
riofujimon
2
600
GitLab CI/CD で C#/WPFアプリケーションのテストとインストーラーのビルド・デプロイを自動化する
hacarus
0
420
Featured
See All Featured
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
21
1.6k
We Have a Design System, Now What?
morganepeng
43
6.8k
[RailsConf 2023] Rails as a piece of cake
palkan
28
4k
Reflections from 52 weeks, 52 projects
jeffersonlam
345
19k
Optimising Largest Contentful Paint
csswizardry
13
2.4k
Art, The Web, and Tiny UX
lynnandtonic
290
19k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
79
43k
How GitHub Uses GitHub to Build GitHub
holman
468
290k
Being A Developer After 40
akosma
67
580k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
660
120k
Building Adaptive Systems
keathley
32
1.9k
Building a Modern Day E-commerce SEO Strategy
aleyda
22
6.4k
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! !