Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Hydra_Internals_12.swift
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