the problem around > Is the single most complex part of any application > reboot? > database inconsistencies? race conditions? UI not updated everywhere? out of order operations? > complex code!
to a value calculated from a and b if some condition is satisfied var c: String var a = 1 var b = 2 if a + b >= 0 { c = "\(a + b) is positive" // 3 is positive } a = -4 // 3 is positive ⁉
// Fetch for a collection with the given title let fetch = PHAssetCollection.fetchCollectionWithTitle(title) // Creates and fetches a new collection with the given title let createAndFetch = PHAssetCollection .createCollectionWithTitle(title) .flatMap { identifier in PHAssetCollection.fetchCollectionWithIdentifier(identifier) } // Retrieves the album with the given title. New or already created! let retreiveAlbum = auth .flatMap { fetch.flatMapError { createAndFetch } retrieveAlbum(name: "BingWallpapers") .flatMap { album in PHPhotoLibrary.saveImage(image, toCollection: collection) }