Handwritten Text Recognition for manuscripts and early printed texts
Futures e abstração - QCon São Paulo 2015
1. LEONARDO BORGES • SENIOR CLOJURE ENGINEER • @LEONARDO_BORGES
O futuro chegou:
Programação concorrente com futures
2. SOBRE
Um pouco sobre mim
• Senior Clojure Engineer na
Atlassian, Sydney
• Fundador do Grupo de Usuários
Clojure de Sydney
• Autor de Clojure Reactive
Programming - http://bit.ly/cljRp
* QCon discount code: CRP10
6. FUTURES EM JAVA <= 1.7
Integer doubled = doubler(serviceA(10).get());
System.out.println("Couldn't do anything else while the line above was being executed...");
System.out.println("Result: " + serviceB(doubled).get() + " - " + serviceC(doubled).get());
Bloqueia a thread
Bloqueia a thread Bloqueia a thread
33. • Java não suporta tipos de alta
espécie (higher kinded types)
• Tipos de alta espécie são
indispensáveis ao se implementar
tais abstrações
Chegando no limite do sistema
de tipos
35. FlatMappable se chama Monad
trait Monad[F[_]] {
def point[A](a: => A): F[A]
def bind[A, B](a: F[A])(f: A => F[B]): F[B]
def map[A, B](a: F[A])(f: A => B): F[B] = bind(a)(b => point(f(b)))
}
36. FlatMappable se chama Monad
trait Monad[F[_]] {
def point[A](a: => A): F[A]
def bind[A, B](a: F[A])(f: A => F[B]): F[B]
def map[A, B](a: F[A])(f: A => B): F[B] = bind(a)(b => point(f(b)))
}
Tipos de alta espécie em ação
37. MONADS EM SCALA
O Monad de Futures
implicit def FutureMonad: Monad[Future] = new Monad[Future] {
def point[A](a: => A) = Future.successful(a)
def bind[A, B](a: Future[A])(f: A => Future[B]): Future[B] = a flatMap f
}
38. MONADS EM SCALA
O Monad de Listas
implicit def ListMonad: Monad[List] = new Monad[List] {
def point[A](a: => A) = List(a)
def bind[A, B](a: List[A])(f: A => List[B]): List[B] = a flatMap f
}
40. Being abstract is something profoundly
different from being vague … The purpose of
abstraction is not to be vague, but to create a
new semantic level in which one can be
absolutely precise.
EDSGER W. DIJKSTRA
”
“
57. Being abstract is something profoundly
different from being vague … The purpose of
abstraction is not to be vague, but to create a
new semantic level in which one can be
absolutely precise.
EDSGER W. DIJKSTRA
”
“