2. I hate monads already. Even if it’s
the most useful, elegant thing - it’s
all what’s wrong about hype based
hipster-programming in one word.
- tweet after UIKonf
3. Is it really functional
programming if you don't give a
talk about it?
- @alejandrocrosa
6. Imperative
Do this 5 times!
func nullToNil(dict: [String: AnyObject])->[String: AnyObject]{
var cleaned = [String: AnyObject]()
for (key, value) in dict {
if !(value is NSNull) {
cleaned[key] = value
}
}
return cleaned
}
7. Functional
Same input, same output.
let l : List<Int> = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
let sum = l.reduce(curry(+), initial: 0) // 55
9. Functional Reactive
Stream of events being processed.
voiceSignal
.filter { response in
return response.intent == WitIntent.Eat
}
.bind(WitResponse.getSubject)
.map{ subject in
self.speak("I will search for recipies for (subject).")
return subject
}
.bind(RecipeSearch().search)
.map { recipes in
self.speak("Please select on of these recipies.")
return recipes
}
.bind(RecipePickerViewController().selectRecipe(self))
.map { ingredients in
self.speak("Do you have all the ingredients or should I order
some online for you?")
return ingredients
}
.bind(ShoppingList.selectIngredients(self))
.bind(Shopping.order)
.bind(PayPalViewController().checkout(self))
13. Question State How to recognise?
IP
imperative
How? a lot of nested loops and assignments
OOP
object oriented
How?
(but encapsulated)
encapsulated
state
seperation of concerns
“unix principle”
POP
protocol oriented
What? encapsulated
objects implementing hundreds
of protocols.
FP
functional
What? no state.
you have no idea what it’s doing,
but it’s short and beautiful.
FRP
functional reactive
When?
over my dead
lambda.
you’re constantly binding
28. The Introduction to RP
you’ve been missing.
https://gist.github.com/staltz/868e7e9bc2a7b8c1f754
29. Imperative Programming In Swift (Graham Lee)
sicpers.info/2015/07/imperative-programming-in-swift/
Protocol-Oriented Programming in Objective-C
sicpers.info/2015/06/protocol-oriented-programming-in-
objective-c/
Mutable objects in immutable objects in object-oriented
programming in functional programming in Swift
sicpers.info/2015/06/mutable-objects-in-immutable-
objects-in-object-oriented-programming-in-functional-
programming-in-swift/