SlideShare a Scribd company logo
Taming Asynchronous
Transforms with
Interstellar
let me = Person(name: "Jens Ravens", company: "nerdgeschoss")
@JensRavens
GitHub: JensRavens
jensravens.com
nerdgeschoss.de
A short introduction to
functional programming, the
universe and everything.
In the beginning McIlroy
created the unix pipe. And he
saw it was good.
ls | grep *.jpg | sort
Optionals
and Results
Optionals are a box containing
something.
struct Cat {
func pet() -> String {
return "purrr"
}
}
let boxContainingCat: Optional<Cat> = Cat()
let sound: String?
if let cat = boxContainingCat {
sound = cat.pet()
} else {
sound = nil
}
struct Cat {
func pet() -> String {
return "purrr"
}
}
let boxContainingCat: Optional<Cat> = Cat()
let sound = boxContainingCat?.pet()
struct Cat {
func pet() -> String {
return "purrr"
}
}
let boxContainingCat: Optional<Cat> = Cat()
let sound = boxContainingCat.map { cat in cat.pet() }
struct Cat {
func pet() -> String? {
return "purrr"
}
}
let boxContainingCat: Optional<Cat> = Cat()
let sound: String?? = boxContainingCat.map {
cat in cat.pet()
}
struct Cat {
func pet() -> String? {
return "purrr"
}
}
let boxContainingCat: Optional<Cat> = Cat()
let sound: String? = boxContainingCat.flatMap {
cat in cat.pet()
}
func double(i: Int) -> [Int] { return [i, 2*i] }
[1, 2, 3].map(double) // [[1,2], [2,4], [3,6]]
[1, 2, 3].flatMap(double) // [[1, 2, 2,4, 3,6]
Error Handling
Buy it, use it,
break it, fix it,
Trash it, change it,
mail - upgrade it.
– Daft Punk, Technologic
Buy it;
if error {
//TODO: Handle me!
} else {
use it;
if error {
//TODO: Handle me!
} else {
break it;
if error {
//TODO: Handle me!
enum Result<T> {
case Success(T)
case Error(ErrorType)
func map<U>(f: T -> U) -> Result<U>
func flatMap<U>(f: T -> Result<U>) -> Result<U>
}
func ls()-> Result<[String]>
func grep(pattern: String)(values: [String]) -> [String]
func sort(values: [String]) -> [String] { return [] }
let sorted = ls().map(grep("*.jpg")).map(sort)
ls | grep *.jpg | sort
Interstellar
ls | grep *.jpg | sort
class Signal<T> {
func subscribe(f: Result<T> -> Void) -> Signal<T>
func next(g: T -> Void) -> Signal<T>
func error(g: ErrorType -> Void) -> Signal<T>
func update(result: Result<T>)
func update(value: T)
func update(error: ErrorType)
}
let signal = Signal<String>()
signal.next { string in print(string) }
signal.update("Hello World")
pushing instead of pulling
But what about
Threads?
let threadSignal = Signal<String>()
func uppercase(string: String) -> String {
return string.uppercaseString
}
threadSignal
.ensure(Thread.background)
.map(uppercase)
.ensure(Thread.main)
.next { print($0) }
Extending UIKit to
support Signals.
extension UITextField {
public var textSignal: Signal<String>
}
let textField = UITextField()
textField.textSignal.next { string in print(string) }
If it’s variable, it qualifies
as a Signal.
real world code examples
func executeRequest(request: Request) -> Signal<HTTPResponse>
func getURL(response: HTTPResponse) throws -> NSURL
func upload(data: NSData)(url: NSURL, completion:
Result<String>->Void)
func createEntity(path: String, completion:
Result<Conversation>->Void)
func createConversation(avatar: UIImage) ->
Signal<Conversation> {
let signal = Signal<Conversation>()
let data = UIImageJPEGRepresentation(avatar, 0.8)!
api
.executeRequest(.GetUploadURL)
.flatMap(getURL)
.flatMap(api.upload(data))
.flatMap(createEntity)
.subscribe(signal.update)
return signal
}
func poll() -> Signal<[Conversation]> {
let signal = Signal<[Conversation]>()
let json = api
.executeRequest(.GetConversations)
.map { $0.json }
let conversations = json
.flatMap(Sync<Conversation>(context: context).updateObjects)
let messages = json
.flatMap(getMessages)
.flatMap(Sync<Message>(context: context).updateObjects)
conversations.merge(messages)
.flatMap(context.saveAndPipe)
.next { signal.update($0.0) }
.error { signal.update($0) }
signal.map(countUnread).next(setUnreadCount)
return signal
}
func poll() -> Signal<[Conversation]> {
let signal = Signal<[Conversation]>()
let json = api
.executeRequest(.GetConversations)
.map { $0.json }
let conversations = json
.flatMap(Sync<Conversation>(context: context).updateObjects)
let messages = json
.flatMap(getMessages)
.flatMap(Sync<Message>(context: context).updateObjects)
conversations.merge(messages)
.flatMap(context.saveAndPipe)
.next { signal.update($0.0) }
.error { signal.update($0) }
signal.map(countUnread).next(setUnreadCount)
return signal
}
API Request
sync conversations
sync messages
wait for both
then save
update unread
count
notify listeners
Warpdrive
• Thread.main / Thread.background
• Signal.delay(seconds: NSTimeInterval)
• Signal.wait throws
• Signal.debounce(seconds: NSTimeInterval)
Coming soon:
Holodeck UIKit Bindings
Thank you.
@JensRavens
github.com/jensravens/interstellar

More Related Content

What's hot

Csharp_Chap13
Csharp_Chap13Csharp_Chap13
Csharp_Chap13
Mohamed Krar
 
The Ring programming language version 1.3 book - Part 25 of 88
The Ring programming language version 1.3 book - Part 25 of 88The Ring programming language version 1.3 book - Part 25 of 88
The Ring programming language version 1.3 book - Part 25 of 88
Mahmoud Samir Fayed
 
The Ring programming language version 1.5.2 book - Part 34 of 181
The Ring programming language version 1.5.2 book - Part 34 of 181The Ring programming language version 1.5.2 book - Part 34 of 181
The Ring programming language version 1.5.2 book - Part 34 of 181
Mahmoud Samir Fayed
 
Cassandra Summit - What's New In Apache TinkerPop?
Cassandra Summit - What's New In Apache TinkerPop?Cassandra Summit - What's New In Apache TinkerPop?
Cassandra Summit - What's New In Apache TinkerPop?
Stephen Mallette
 
The Ring programming language version 1.5.4 book - Part 23 of 185
The Ring programming language version 1.5.4 book - Part 23 of 185The Ring programming language version 1.5.4 book - Part 23 of 185
The Ring programming language version 1.5.4 book - Part 23 of 185
Mahmoud Samir Fayed
 
Hw09 Hadoop + Clojure
Hw09   Hadoop + ClojureHw09   Hadoop + Clojure
Hw09 Hadoop + Clojure
Cloudera, Inc.
 
The Ring programming language version 1.5.4 book - Part 35 of 185
The Ring programming language version 1.5.4 book - Part 35 of 185The Ring programming language version 1.5.4 book - Part 35 of 185
The Ring programming language version 1.5.4 book - Part 35 of 185
Mahmoud Samir Fayed
 
Functional Programming inside OOP? It’s possible with Python
Functional Programming inside OOP? It’s possible with PythonFunctional Programming inside OOP? It’s possible with Python
Functional Programming inside OOP? It’s possible with Python
Carlos V.
 
The Ring programming language version 1.10 book - Part 43 of 212
The Ring programming language version 1.10 book - Part 43 of 212The Ring programming language version 1.10 book - Part 43 of 212
The Ring programming language version 1.10 book - Part 43 of 212
Mahmoud Samir Fayed
 
Phil Bartie QGIS PLPython
Phil Bartie QGIS PLPythonPhil Bartie QGIS PLPython
Phil Bartie QGIS PLPython
Ross McDonald
 
Go ahead, make my day
Go ahead, make my dayGo ahead, make my day
Go ahead, make my day
Tor Ivry
 
The Ring programming language version 1.10 book - Part 31 of 212
The Ring programming language version 1.10 book - Part 31 of 212The Ring programming language version 1.10 book - Part 31 of 212
The Ring programming language version 1.10 book - Part 31 of 212
Mahmoud Samir Fayed
 
Beyond tf idf why, what & how
Beyond tf idf why, what & howBeyond tf idf why, what & how
Beyond tf idf why, what & how
lucenerevolution
 
The Ring programming language version 1.5.1 book - Part 33 of 180
The Ring programming language version 1.5.1 book - Part 33 of 180The Ring programming language version 1.5.1 book - Part 33 of 180
The Ring programming language version 1.5.1 book - Part 33 of 180
Mahmoud Samir Fayed
 
OCamlOScope: a New OCaml API Search
OCamlOScope: a New OCaml API SearchOCamlOScope: a New OCaml API Search
OCamlOScope: a New OCaml API Search
Jun Furuse
 
F# Presentation for SmartDevs, Hereford
F# Presentation for SmartDevs, HerefordF# Presentation for SmartDevs, Hereford
F# Presentation for SmartDevs, Hereford
Kit Eason
 
Data made out of functions
Data made out of functionsData made out of functions
Data made out of functions
kenbot
 
The Ring programming language version 1.6 book - Part 37 of 189
The Ring programming language version 1.6 book - Part 37 of 189The Ring programming language version 1.6 book - Part 37 of 189
The Ring programming language version 1.6 book - Part 37 of 189
Mahmoud Samir Fayed
 
ScalaMeter 2014
ScalaMeter 2014ScalaMeter 2014
ScalaMeter 2014
Aleksandar Prokopec
 
Curry functions in Javascript
Curry functions in JavascriptCurry functions in Javascript
Curry functions in Javascript
Anand Kumar
 

What's hot (20)

Csharp_Chap13
Csharp_Chap13Csharp_Chap13
Csharp_Chap13
 
The Ring programming language version 1.3 book - Part 25 of 88
The Ring programming language version 1.3 book - Part 25 of 88The Ring programming language version 1.3 book - Part 25 of 88
The Ring programming language version 1.3 book - Part 25 of 88
 
The Ring programming language version 1.5.2 book - Part 34 of 181
The Ring programming language version 1.5.2 book - Part 34 of 181The Ring programming language version 1.5.2 book - Part 34 of 181
The Ring programming language version 1.5.2 book - Part 34 of 181
 
Cassandra Summit - What's New In Apache TinkerPop?
Cassandra Summit - What's New In Apache TinkerPop?Cassandra Summit - What's New In Apache TinkerPop?
Cassandra Summit - What's New In Apache TinkerPop?
 
The Ring programming language version 1.5.4 book - Part 23 of 185
The Ring programming language version 1.5.4 book - Part 23 of 185The Ring programming language version 1.5.4 book - Part 23 of 185
The Ring programming language version 1.5.4 book - Part 23 of 185
 
Hw09 Hadoop + Clojure
Hw09   Hadoop + ClojureHw09   Hadoop + Clojure
Hw09 Hadoop + Clojure
 
The Ring programming language version 1.5.4 book - Part 35 of 185
The Ring programming language version 1.5.4 book - Part 35 of 185The Ring programming language version 1.5.4 book - Part 35 of 185
The Ring programming language version 1.5.4 book - Part 35 of 185
 
Functional Programming inside OOP? It’s possible with Python
Functional Programming inside OOP? It’s possible with PythonFunctional Programming inside OOP? It’s possible with Python
Functional Programming inside OOP? It’s possible with Python
 
The Ring programming language version 1.10 book - Part 43 of 212
The Ring programming language version 1.10 book - Part 43 of 212The Ring programming language version 1.10 book - Part 43 of 212
The Ring programming language version 1.10 book - Part 43 of 212
 
Phil Bartie QGIS PLPython
Phil Bartie QGIS PLPythonPhil Bartie QGIS PLPython
Phil Bartie QGIS PLPython
 
Go ahead, make my day
Go ahead, make my dayGo ahead, make my day
Go ahead, make my day
 
The Ring programming language version 1.10 book - Part 31 of 212
The Ring programming language version 1.10 book - Part 31 of 212The Ring programming language version 1.10 book - Part 31 of 212
The Ring programming language version 1.10 book - Part 31 of 212
 
Beyond tf idf why, what & how
Beyond tf idf why, what & howBeyond tf idf why, what & how
Beyond tf idf why, what & how
 
The Ring programming language version 1.5.1 book - Part 33 of 180
The Ring programming language version 1.5.1 book - Part 33 of 180The Ring programming language version 1.5.1 book - Part 33 of 180
The Ring programming language version 1.5.1 book - Part 33 of 180
 
OCamlOScope: a New OCaml API Search
OCamlOScope: a New OCaml API SearchOCamlOScope: a New OCaml API Search
OCamlOScope: a New OCaml API Search
 
F# Presentation for SmartDevs, Hereford
F# Presentation for SmartDevs, HerefordF# Presentation for SmartDevs, Hereford
F# Presentation for SmartDevs, Hereford
 
Data made out of functions
Data made out of functionsData made out of functions
Data made out of functions
 
The Ring programming language version 1.6 book - Part 37 of 189
The Ring programming language version 1.6 book - Part 37 of 189The Ring programming language version 1.6 book - Part 37 of 189
The Ring programming language version 1.6 book - Part 37 of 189
 
ScalaMeter 2014
ScalaMeter 2014ScalaMeter 2014
ScalaMeter 2014
 
Curry functions in Javascript
Curry functions in JavascriptCurry functions in Javascript
Curry functions in Javascript
 

Viewers also liked

Presentazione Tambeach
Presentazione Tambeach Presentazione Tambeach
Presentazione Tambeach
Nada Vallone
 
Business finance
Business financeBusiness finance
Business finance
VijaySomasePatil
 
Productive Android developers (Meetup slides)
Productive Android developers (Meetup slides)Productive Android developers (Meetup slides)
Productive Android developers (Meetup slides)
Michal Juhas
 
през цапукда ярославль тур 271216_резюме
през цапукда ярославль тур 271216_резюмепрез цапукда ярославль тур 271216_резюме
през цапукда ярославль тур 271216_резюме
Дмитрий Цапук
 
Thriller development paul
Thriller development paulThriller development paul
Thriller development paul
Paul Abustan
 
FPBP Brochure - Get Care Get Covered
FPBP Brochure - Get Care Get CoveredFPBP Brochure - Get Care Get Covered
FPBP Brochure - Get Care Get Covered
Andrew Jones
 
Building Business – Marketing Candidates
Building Business – Marketing CandidatesBuilding Business – Marketing Candidates
Building Business – Marketing Candidates
Rebecca Sargeant
 
Přednáška V3C: Vyhodnocení dotazníků
Přednáška V3C: Vyhodnocení dotazníkůPřednáška V3C: Vyhodnocení dotazníků
Přednáška V3C: Vyhodnocení dotazníků
Jaroslav Prodelal
 
Nikhil Bagde Software Engineer
Nikhil Bagde Software EngineerNikhil Bagde Software Engineer
Nikhil Bagde Software Engineer
Nikhil Bagde
 
Kerääjäkasveilla ravinteet talteen, Sari Iivonen, Helsingin yliopisto
Kerääjäkasveilla ravinteet talteen, Sari Iivonen, Helsingin yliopistoKerääjäkasveilla ravinteet talteen, Sari Iivonen, Helsingin yliopisto
Kerääjäkasveilla ravinteet talteen, Sari Iivonen, Helsingin yliopisto
Natural Resources Institute Finland (Luke) / Luonnonvarakeskus (Luke)
 

Viewers also liked (11)

Presentazione Tambeach
Presentazione Tambeach Presentazione Tambeach
Presentazione Tambeach
 
Business finance
Business financeBusiness finance
Business finance
 
Productive Android developers (Meetup slides)
Productive Android developers (Meetup slides)Productive Android developers (Meetup slides)
Productive Android developers (Meetup slides)
 
през цапукда ярославль тур 271216_резюме
през цапукда ярославль тур 271216_резюмепрез цапукда ярославль тур 271216_резюме
през цапукда ярославль тур 271216_резюме
 
Thriller development paul
Thriller development paulThriller development paul
Thriller development paul
 
FPBP Brochure - Get Care Get Covered
FPBP Brochure - Get Care Get CoveredFPBP Brochure - Get Care Get Covered
FPBP Brochure - Get Care Get Covered
 
Building Business – Marketing Candidates
Building Business – Marketing CandidatesBuilding Business – Marketing Candidates
Building Business – Marketing Candidates
 
Ben
BenBen
Ben
 
Přednáška V3C: Vyhodnocení dotazníků
Přednáška V3C: Vyhodnocení dotazníkůPřednáška V3C: Vyhodnocení dotazníků
Přednáška V3C: Vyhodnocení dotazníků
 
Nikhil Bagde Software Engineer
Nikhil Bagde Software EngineerNikhil Bagde Software Engineer
Nikhil Bagde Software Engineer
 
Kerääjäkasveilla ravinteet talteen, Sari Iivonen, Helsingin yliopisto
Kerääjäkasveilla ravinteet talteen, Sari Iivonen, Helsingin yliopistoKerääjäkasveilla ravinteet talteen, Sari Iivonen, Helsingin yliopisto
Kerääjäkasveilla ravinteet talteen, Sari Iivonen, Helsingin yliopisto
 

Similar to Taming Asynchronous Transforms with Interstellar

Monadologie
MonadologieMonadologie
Monadologie
league
 
Kotlin Advanced - Apalon Kotlin Sprint Part 3
Kotlin Advanced - Apalon Kotlin Sprint Part 3Kotlin Advanced - Apalon Kotlin Sprint Part 3
Kotlin Advanced - Apalon Kotlin Sprint Part 3
Kirill Rozov
 
Scala - where objects and functions meet
Scala - where objects and functions meetScala - where objects and functions meet
Scala - where objects and functions meet
Mario Fusco
 
Functional Reactive Programming without Black Magic (UIKonf 2015)
Functional Reactive Programming without Black Magic (UIKonf 2015)Functional Reactive Programming without Black Magic (UIKonf 2015)
Functional Reactive Programming without Black Magic (UIKonf 2015)
Jens Ravens
 
SDC - Einführung in Scala
SDC - Einführung in ScalaSDC - Einführung in Scala
SDC - Einführung in Scala
Christian Baranowski
 
The Ring programming language version 1.3 book - Part 26 of 88
The Ring programming language version 1.3 book - Part 26 of 88The Ring programming language version 1.3 book - Part 26 of 88
The Ring programming language version 1.3 book - Part 26 of 88
Mahmoud Samir Fayed
 
Scala presentation by Aleksandar Prokopec
Scala presentation by Aleksandar ProkopecScala presentation by Aleksandar Prokopec
Scala presentation by Aleksandar Prokopec
Loïc Descotte
 
Swift 함수 커링 사용하기
Swift 함수 커링 사용하기Swift 함수 커링 사용하기
Swift 함수 커링 사용하기
진성 오
 
Scala 2 + 2 > 4
Scala 2 + 2 > 4Scala 2 + 2 > 4
Scala 2 + 2 > 4
Emil Vladev
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to Scala
Aleksandar Prokopec
 
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdfpragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
Hiroshi Ono
 
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdfpragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
Hiroshi Ono
 
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdfpragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
Hiroshi Ono
 
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdfpragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
Hiroshi Ono
 
A Prelude of Purity: Scaling Back ZIO
A Prelude of Purity: Scaling Back ZIOA Prelude of Purity: Scaling Back ZIO
A Prelude of Purity: Scaling Back ZIO
Jorge Vásquez
 
Idiomatic Kotlin
Idiomatic KotlinIdiomatic Kotlin
Idiomatic Kotlin
intelliyole
 
Are we ready to Go?
Are we ready to Go?Are we ready to Go?
Are we ready to Go?
Adam Dudczak
 
Functions In Scala
Functions In Scala Functions In Scala
Functions In Scala
Knoldus Inc.
 
3 kotlin vs. java- what kotlin has that java does not
3  kotlin vs. java- what kotlin has that java does not3  kotlin vs. java- what kotlin has that java does not
3 kotlin vs. java- what kotlin has that java does not
Sergey Bandysik
 
Functional programming ii
Functional programming iiFunctional programming ii
Functional programming ii
Prashant Kalkar
 

Similar to Taming Asynchronous Transforms with Interstellar (20)

Monadologie
MonadologieMonadologie
Monadologie
 
Kotlin Advanced - Apalon Kotlin Sprint Part 3
Kotlin Advanced - Apalon Kotlin Sprint Part 3Kotlin Advanced - Apalon Kotlin Sprint Part 3
Kotlin Advanced - Apalon Kotlin Sprint Part 3
 
Scala - where objects and functions meet
Scala - where objects and functions meetScala - where objects and functions meet
Scala - where objects and functions meet
 
Functional Reactive Programming without Black Magic (UIKonf 2015)
Functional Reactive Programming without Black Magic (UIKonf 2015)Functional Reactive Programming without Black Magic (UIKonf 2015)
Functional Reactive Programming without Black Magic (UIKonf 2015)
 
SDC - Einführung in Scala
SDC - Einführung in ScalaSDC - Einführung in Scala
SDC - Einführung in Scala
 
The Ring programming language version 1.3 book - Part 26 of 88
The Ring programming language version 1.3 book - Part 26 of 88The Ring programming language version 1.3 book - Part 26 of 88
The Ring programming language version 1.3 book - Part 26 of 88
 
Scala presentation by Aleksandar Prokopec
Scala presentation by Aleksandar ProkopecScala presentation by Aleksandar Prokopec
Scala presentation by Aleksandar Prokopec
 
Swift 함수 커링 사용하기
Swift 함수 커링 사용하기Swift 함수 커링 사용하기
Swift 함수 커링 사용하기
 
Scala 2 + 2 > 4
Scala 2 + 2 > 4Scala 2 + 2 > 4
Scala 2 + 2 > 4
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to Scala
 
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdfpragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
 
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdfpragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
 
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdfpragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
 
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdfpragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
 
A Prelude of Purity: Scaling Back ZIO
A Prelude of Purity: Scaling Back ZIOA Prelude of Purity: Scaling Back ZIO
A Prelude of Purity: Scaling Back ZIO
 
Idiomatic Kotlin
Idiomatic KotlinIdiomatic Kotlin
Idiomatic Kotlin
 
Are we ready to Go?
Are we ready to Go?Are we ready to Go?
Are we ready to Go?
 
Functions In Scala
Functions In Scala Functions In Scala
Functions In Scala
 
3 kotlin vs. java- what kotlin has that java does not
3  kotlin vs. java- what kotlin has that java does not3  kotlin vs. java- what kotlin has that java does not
3 kotlin vs. java- what kotlin has that java does not
 
Functional programming ii
Functional programming iiFunctional programming ii
Functional programming ii
 

More from Jens Ravens

Turning it up to 11 - Scaling Ruby on Rails to 100k rps
Turning it up to 11 - Scaling Ruby on Rails to 100k rpsTurning it up to 11 - Scaling Ruby on Rails to 100k rps
Turning it up to 11 - Scaling Ruby on Rails to 100k rps
Jens Ravens
 
Server Side Swift - AppBuilders 2017
Server Side Swift - AppBuilders 2017Server Side Swift - AppBuilders 2017
Server Side Swift - AppBuilders 2017
Jens Ravens
 
Server Side Swift
Server Side SwiftServer Side Swift
Server Side Swift
Jens Ravens
 
Working with Xcode and Swift Package Manager
Working with Xcode and Swift Package ManagerWorking with Xcode and Swift Package Manager
Working with Xcode and Swift Package Manager
Jens Ravens
 
Server Side Swift with Swag
Server Side Swift with SwagServer Side Swift with Swag
Server Side Swift with Swag
Jens Ravens
 
Hipster oriented programming (Mobilization Lodz 2015)
Hipster oriented programming (Mobilization Lodz 2015)Hipster oriented programming (Mobilization Lodz 2015)
Hipster oriented programming (Mobilization Lodz 2015)
Jens Ravens
 
Hipster Oriented Programming
Hipster Oriented ProgrammingHipster Oriented Programming
Hipster Oriented Programming
Jens Ravens
 
Swift 2
Swift 2Swift 2
Swift 2
Jens Ravens
 
Swift: Immutability and You
Swift: Immutability and YouSwift: Immutability and You
Swift: Immutability and You
Jens Ravens
 

More from Jens Ravens (9)

Turning it up to 11 - Scaling Ruby on Rails to 100k rps
Turning it up to 11 - Scaling Ruby on Rails to 100k rpsTurning it up to 11 - Scaling Ruby on Rails to 100k rps
Turning it up to 11 - Scaling Ruby on Rails to 100k rps
 
Server Side Swift - AppBuilders 2017
Server Side Swift - AppBuilders 2017Server Side Swift - AppBuilders 2017
Server Side Swift - AppBuilders 2017
 
Server Side Swift
Server Side SwiftServer Side Swift
Server Side Swift
 
Working with Xcode and Swift Package Manager
Working with Xcode and Swift Package ManagerWorking with Xcode and Swift Package Manager
Working with Xcode and Swift Package Manager
 
Server Side Swift with Swag
Server Side Swift with SwagServer Side Swift with Swag
Server Side Swift with Swag
 
Hipster oriented programming (Mobilization Lodz 2015)
Hipster oriented programming (Mobilization Lodz 2015)Hipster oriented programming (Mobilization Lodz 2015)
Hipster oriented programming (Mobilization Lodz 2015)
 
Hipster Oriented Programming
Hipster Oriented ProgrammingHipster Oriented Programming
Hipster Oriented Programming
 
Swift 2
Swift 2Swift 2
Swift 2
 
Swift: Immutability and You
Swift: Immutability and YouSwift: Immutability and You
Swift: Immutability and You
 

Recently uploaded

Oracle 23c New Features For DBAs and Developers.pptx
Oracle 23c New Features For DBAs and Developers.pptxOracle 23c New Features For DBAs and Developers.pptx
Oracle 23c New Features For DBAs and Developers.pptx
Remote DBA Services
 
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
mz5nrf0n
 
Modelling Up - DDDEurope 2024 - Amsterdam
Modelling Up - DDDEurope 2024 - AmsterdamModelling Up - DDDEurope 2024 - Amsterdam
Modelling Up - DDDEurope 2024 - Amsterdam
Alberto Brandolini
 
GreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-JurisicGreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-Jurisic
Green Software Development
 
All you need to know about Spring Boot and GraalVM
All you need to know about Spring Boot and GraalVMAll you need to know about Spring Boot and GraalVM
All you need to know about Spring Boot and GraalVM
Alina Yurenko
 
SQL Accounting Software Brochure Malaysia
SQL Accounting Software Brochure MalaysiaSQL Accounting Software Brochure Malaysia
SQL Accounting Software Brochure Malaysia
GohKiangHock
 
J-Spring 2024 - Going serverless with Quarkus, GraalVM native images and AWS ...
J-Spring 2024 - Going serverless with Quarkus, GraalVM native images and AWS ...J-Spring 2024 - Going serverless with Quarkus, GraalVM native images and AWS ...
J-Spring 2024 - Going serverless with Quarkus, GraalVM native images and AWS ...
Bert Jan Schrijver
 
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, FactsALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
Green Software Development
 
How to write a program in any programming language
How to write a program in any programming languageHow to write a program in any programming language
How to write a program in any programming language
Rakesh Kumar R
 
zOS Mainframe JES2-JES3 JCL-JECL Differences
zOS Mainframe JES2-JES3 JCL-JECL DifferenceszOS Mainframe JES2-JES3 JCL-JECL Differences
zOS Mainframe JES2-JES3 JCL-JECL Differences
YousufSait3
 
Using Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional SafetyUsing Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional Safety
Ayan Halder
 
Malibou Pitch Deck For Its €3M Seed Round
Malibou Pitch Deck For Its €3M Seed RoundMalibou Pitch Deck For Its €3M Seed Round
Malibou Pitch Deck For Its €3M Seed Round
sjcobrien
 
在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样
在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样
在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样
mz5nrf0n
 
Lecture 2 - software testing SE 412.pptx
Lecture 2 - software testing SE 412.pptxLecture 2 - software testing SE 412.pptx
Lecture 2 - software testing SE 412.pptx
TaghreedAltamimi
 
socradar-q1-2024-aviation-industry-report.pdf
socradar-q1-2024-aviation-industry-report.pdfsocradar-q1-2024-aviation-industry-report.pdf
socradar-q1-2024-aviation-industry-report.pdf
SOCRadar
 
Mobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona InfotechMobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona Infotech
Drona Infotech
 
Microservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we workMicroservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we work
Sven Peters
 
Unveiling the Advantages of Agile Software Development.pdf
Unveiling the Advantages of Agile Software Development.pdfUnveiling the Advantages of Agile Software Development.pdf
Unveiling the Advantages of Agile Software Development.pdf
brainerhub1
 
Enums On Steroids - let's look at sealed classes !
Enums On Steroids - let's look at sealed classes !Enums On Steroids - let's look at sealed classes !
Enums On Steroids - let's look at sealed classes !
Marcin Chrost
 
Oracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptxOracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptx
Remote DBA Services
 

Recently uploaded (20)

Oracle 23c New Features For DBAs and Developers.pptx
Oracle 23c New Features For DBAs and Developers.pptxOracle 23c New Features For DBAs and Developers.pptx
Oracle 23c New Features For DBAs and Developers.pptx
 
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
 
Modelling Up - DDDEurope 2024 - Amsterdam
Modelling Up - DDDEurope 2024 - AmsterdamModelling Up - DDDEurope 2024 - Amsterdam
Modelling Up - DDDEurope 2024 - Amsterdam
 
GreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-JurisicGreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-Jurisic
 
All you need to know about Spring Boot and GraalVM
All you need to know about Spring Boot and GraalVMAll you need to know about Spring Boot and GraalVM
All you need to know about Spring Boot and GraalVM
 
SQL Accounting Software Brochure Malaysia
SQL Accounting Software Brochure MalaysiaSQL Accounting Software Brochure Malaysia
SQL Accounting Software Brochure Malaysia
 
J-Spring 2024 - Going serverless with Quarkus, GraalVM native images and AWS ...
J-Spring 2024 - Going serverless with Quarkus, GraalVM native images and AWS ...J-Spring 2024 - Going serverless with Quarkus, GraalVM native images and AWS ...
J-Spring 2024 - Going serverless with Quarkus, GraalVM native images and AWS ...
 
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, FactsALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
 
How to write a program in any programming language
How to write a program in any programming languageHow to write a program in any programming language
How to write a program in any programming language
 
zOS Mainframe JES2-JES3 JCL-JECL Differences
zOS Mainframe JES2-JES3 JCL-JECL DifferenceszOS Mainframe JES2-JES3 JCL-JECL Differences
zOS Mainframe JES2-JES3 JCL-JECL Differences
 
Using Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional SafetyUsing Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional Safety
 
Malibou Pitch Deck For Its €3M Seed Round
Malibou Pitch Deck For Its €3M Seed RoundMalibou Pitch Deck For Its €3M Seed Round
Malibou Pitch Deck For Its €3M Seed Round
 
在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样
在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样
在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样
 
Lecture 2 - software testing SE 412.pptx
Lecture 2 - software testing SE 412.pptxLecture 2 - software testing SE 412.pptx
Lecture 2 - software testing SE 412.pptx
 
socradar-q1-2024-aviation-industry-report.pdf
socradar-q1-2024-aviation-industry-report.pdfsocradar-q1-2024-aviation-industry-report.pdf
socradar-q1-2024-aviation-industry-report.pdf
 
Mobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona InfotechMobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona Infotech
 
Microservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we workMicroservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we work
 
Unveiling the Advantages of Agile Software Development.pdf
Unveiling the Advantages of Agile Software Development.pdfUnveiling the Advantages of Agile Software Development.pdf
Unveiling the Advantages of Agile Software Development.pdf
 
Enums On Steroids - let's look at sealed classes !
Enums On Steroids - let's look at sealed classes !Enums On Steroids - let's look at sealed classes !
Enums On Steroids - let's look at sealed classes !
 
Oracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptxOracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptx
 

Taming Asynchronous Transforms with Interstellar

  • 2. let me = Person(name: "Jens Ravens", company: "nerdgeschoss") @JensRavens GitHub: JensRavens jensravens.com nerdgeschoss.de
  • 3. A short introduction to functional programming, the universe and everything.
  • 4. In the beginning McIlroy created the unix pipe. And he saw it was good. ls | grep *.jpg | sort
  • 6. Optionals are a box containing something.
  • 7. struct Cat { func pet() -> String { return "purrr" } } let boxContainingCat: Optional<Cat> = Cat() let sound: String? if let cat = boxContainingCat { sound = cat.pet() } else { sound = nil }
  • 8. struct Cat { func pet() -> String { return "purrr" } } let boxContainingCat: Optional<Cat> = Cat() let sound = boxContainingCat?.pet()
  • 9. struct Cat { func pet() -> String { return "purrr" } } let boxContainingCat: Optional<Cat> = Cat() let sound = boxContainingCat.map { cat in cat.pet() }
  • 10. struct Cat { func pet() -> String? { return "purrr" } } let boxContainingCat: Optional<Cat> = Cat() let sound: String?? = boxContainingCat.map { cat in cat.pet() }
  • 11. struct Cat { func pet() -> String? { return "purrr" } } let boxContainingCat: Optional<Cat> = Cat() let sound: String? = boxContainingCat.flatMap { cat in cat.pet() }
  • 12. func double(i: Int) -> [Int] { return [i, 2*i] } [1, 2, 3].map(double) // [[1,2], [2,4], [3,6]] [1, 2, 3].flatMap(double) // [[1, 2, 2,4, 3,6]
  • 14. Buy it, use it, break it, fix it, Trash it, change it, mail - upgrade it. – Daft Punk, Technologic
  • 15. Buy it; if error { //TODO: Handle me! } else { use it; if error { //TODO: Handle me! } else { break it; if error { //TODO: Handle me!
  • 16. enum Result<T> { case Success(T) case Error(ErrorType) func map<U>(f: T -> U) -> Result<U> func flatMap<U>(f: T -> Result<U>) -> Result<U> }
  • 17. func ls()-> Result<[String]> func grep(pattern: String)(values: [String]) -> [String] func sort(values: [String]) -> [String] { return [] } let sorted = ls().map(grep("*.jpg")).map(sort) ls | grep *.jpg | sort
  • 19. ls | grep *.jpg | sort
  • 20. class Signal<T> { func subscribe(f: Result<T> -> Void) -> Signal<T> func next(g: T -> Void) -> Signal<T> func error(g: ErrorType -> Void) -> Signal<T> func update(result: Result<T>) func update(value: T) func update(error: ErrorType) } let signal = Signal<String>() signal.next { string in print(string) } signal.update("Hello World")
  • 23. let threadSignal = Signal<String>() func uppercase(string: String) -> String { return string.uppercaseString } threadSignal .ensure(Thread.background) .map(uppercase) .ensure(Thread.main) .next { print($0) }
  • 25. extension UITextField { public var textSignal: Signal<String> } let textField = UITextField() textField.textSignal.next { string in print(string) }
  • 26. If it’s variable, it qualifies as a Signal.
  • 27. real world code examples
  • 28. func executeRequest(request: Request) -> Signal<HTTPResponse> func getURL(response: HTTPResponse) throws -> NSURL func upload(data: NSData)(url: NSURL, completion: Result<String>->Void) func createEntity(path: String, completion: Result<Conversation>->Void) func createConversation(avatar: UIImage) -> Signal<Conversation> { let signal = Signal<Conversation>() let data = UIImageJPEGRepresentation(avatar, 0.8)! api .executeRequest(.GetUploadURL) .flatMap(getURL) .flatMap(api.upload(data)) .flatMap(createEntity) .subscribe(signal.update) return signal }
  • 29. func poll() -> Signal<[Conversation]> { let signal = Signal<[Conversation]>() let json = api .executeRequest(.GetConversations) .map { $0.json } let conversations = json .flatMap(Sync<Conversation>(context: context).updateObjects) let messages = json .flatMap(getMessages) .flatMap(Sync<Message>(context: context).updateObjects) conversations.merge(messages) .flatMap(context.saveAndPipe) .next { signal.update($0.0) } .error { signal.update($0) } signal.map(countUnread).next(setUnreadCount) return signal }
  • 30. func poll() -> Signal<[Conversation]> { let signal = Signal<[Conversation]>() let json = api .executeRequest(.GetConversations) .map { $0.json } let conversations = json .flatMap(Sync<Conversation>(context: context).updateObjects) let messages = json .flatMap(getMessages) .flatMap(Sync<Message>(context: context).updateObjects) conversations.merge(messages) .flatMap(context.saveAndPipe) .next { signal.update($0.0) } .error { signal.update($0) } signal.map(countUnread).next(setUnreadCount) return signal } API Request sync conversations sync messages wait for both then save update unread count notify listeners
  • 32. • Thread.main / Thread.background • Signal.delay(seconds: NSTimeInterval) • Signal.wait throws • Signal.debounce(seconds: NSTimeInterval) Coming soon: Holodeck UIKit Bindings