Tutorial by Examples

Given a Person struct struct Person { let name: String let birthYear: Int? } and an Array of Person(s) let persons = [ Person(name: "Walter White", birthYear: 1959), Person(name: "Jesse Pinkman", birthYear: 1984), Person(name: "Skyler White&quo...
let numbers = [3, 1, 4, 1, 5] // non-functional for (index, element) in numbers.enumerate() { print(index, element) } // functional numbers.enumerate().map { (index, element) in print((index, element)) }
Applying a function to a collection/stream and creating a new collection/stream is called a projection. /// Projection var newReleases = [ [ "id": 70111470, "title": "Die Hard", "boxart": "http://cdn-0.nflximg.com/images...
Create a stream by selecting the elements from a stream that pass a certain condition is called filtering var newReleases = [ [ "id": 70111470, "title": "Die Hard", "boxart": "http://cdn-0.nflximg.com/images/2891/DieHard.j...
Frequently you may want to filter structures and other complex data types. Searching an array of structs for entries that contain a particular value is a very common task, and easily achieved in Swift using functional programming features. What's more, the code is extremely succinct. struct Painter...

Page 1 of 1