multiple return values • Generics • Fast and concise iteration over a range or collection • Structs that support methods, extensions, and protocols • Functional programming patterns, e.g., map and filter • Powerful error handling built-in • Advanced control flow with do, guard, defer, and repeat keywords 10
computation as the evaluation of mathematical functions and avoids changing state and mutable data. paradigm. (n) A worldview underlying the theories and methodology of a particular scientific subject 13
sequence of actions Object-oriented programming - decomposing problems into self-contained properties and methods to manipulate them Functional programming - decomposing problems into functions that accept and return immutable values Generic programming - general purpose algorithms that can be applied to arbitrary types http://robnapier.net/swift-is-not-functional 14
least one of the following: - takes one or more functions as arguments - returns a function as its result Examples: - map, flatMap - filter - reduce 15
value that will exist (or will fail with an error) at some point in the future. • Similar to how an Optional represents a value that may or may not exist. let usersPromise = fetchUsers() // Promise<[User]> usersPromise.then({ users in self.users = users }) https://github.com/khanlou/Promise 21
in the category of endofunctors of X, with product × [operation] replaced by composition of endofunctors and unit set by the identity endofunctor." — Saunders MacLane, Categories for the Working Mathematician http://www-news.uchicago.edu/releases/05/050421.maclane.jpg 30
M×M→M and a special element 1 ∈ M such that 1 and x⋅y=μ(x,y) satisfy the usual axioms of associativity: * (x⋅y)⋅z=x⋅(y⋅z) and the left and right unit laws: * 1⋅x = x = x⋅1 38
typealias B = Int struct Product<A,B> { let a: A let b: B } let projectionA: (Product<A,B>) -> A = { $0.a } let projectionB: (Product<A,B>) -> B = { $0.b } let prod = Product(a: "Hello", b: 3) projectionA(prod) // "Hello" projectionB(prod) // 3 42
Coproduct<A,B> { case a(A) case b(B) } let injectA: (A) -> Coproduct<A,B> = { .a($0) } let injectB: (B) -> Coproduct<A,B> = { .b($0) } let left = "left" let right = 3 injectA(left) // a("left") injectB(right) // b(3) 44
“container” of some sort, along with the ability to apply a function uniformly to every element in the container. For example, a list is a container of elements, and we can apply a function to every element of a list, using map. https://wiki.haskell.org/Typeclassopedia 53
as an enemy you have to fight, but as a tool that guides you almost magically to a solution for your problem, one step at a time, using types. — Ole Begemann .then { users -> ??? in //??? } .then { lucys -> ??? in //??? } https://oleb.net/blog/2015/07/swift-type-system/ 74
a "monad" • We use monads all the time • Swift has monads built in, but extending your type to be a monad is simple • There's lots more category theory out there • Closures and maps allow us to embrace our type system 76