Skip to content
Victor Shamanov edited this page Mar 12, 2015 · 2 revisions

##Functional Composition

###map

Creates a new future by applying a function to the successful result of this future

func map<U>(f: T -> U) -> Future<U, E>

###flatMap

Creates a new future by applying a function to the successful result of this future, and returns the result of the function as the new future

func flatMap<U>(f: T -> Future<U, E>) -> Future<U, E>

###filter

Creates a new future by filtering the value of the current future with a predicate

func filter(p: T -> Bool) -> Future<T?, E>

###zip

Zips the values of this and that future, and creates a new future holding the tuple of their results

func zip<U>(x: Future<U, E>) -> Future<(T, U), E>

###reduce

Return the result of repeatedly calling combine with an accumulated value initialized to initial and each element of Array of Futures, in turn.

func reduce<U>(fxs: [Future<T, E>], initial: U, combine: (U, T) -> U) -> Future<U, E>

###traverse

Transforms a [T] into a Future<[U], E> using the provided function T -> Future<U, E>

func traverse<U>(xs: [T], f: T -> Future<U, E>) -> Future<[U], E>

###sequence

Simple version of Future.traverse

func sequece(fxs: [Future<T, E>]) -> Future<[T], E>

##Recovering errors

###recover

Creates a new future that will handle any matching throwable that this future might contain

func recover(r: E -> T) -> Future<T, E>

###recoverWith

Creates a new future that will handle any matching throwable that this future might contain by assigning it a value of another future

func recoverWith(r: E -> Future<T, E>) -> Future<T, E>
Clone this wiki locally