Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
public func map_series<A, B, S: Sequence>(context: Context, items: S, transform: @escaping (A) throws -> Promise<B>) -> Promise<[B]> where S.Iterator.Element == A {
let initial = Promise<[B]>(resolved: [])
return items.reduce(initial) { chain, item in
return chain.then(in: context) { results in
try transform(item).then(in: context) { results + [$0] }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.