Created
February 4, 2017 11:17
-
-
Save malcommac/fad095cf4d09f9b3adef36fe4e2a1793 to your computer and use it in GitHub Desktop.
Hydra_Internals_12.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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