Instance Method
mapEach(_:)
Gets the value of a key path for each element in the sequence that is wrapped by an
EventLoopFuture.func mapEach<Result>(_ keyPath: KeyPath<Value.Element, Result>) -> EventLoopFuture<[Result]>
Parameters
keyPathThe key path to access on each element in the sequence.
Return Value
A new EventLoopFuture that wraps the sequence of key path values.
Discussion
let collection = eventLoop.future(["a", "bb", "ccc", "dddd", "eeeee"])
let lengths = collection.mapEach(\.count)
// lengths: EventLoopFuture([1, 2, 3, 4, 5])
See Also
EventLoopFuture
class EventLoopFutureQueueAllows you to queue closures that produce anEventLoopFuture, so each future only gets run if the previous ones complete, succeed, or fail.func mapEach<Result>((Value.Element) -> Result) -> EventLoopFuture<[Result]>Calls a closure on each element in the sequence that is wrapped by anEventLoopFuture.func mapEachCompact<Result>(KeyPath<Value.Element, Result?>) -> EventLoopFuture<[Result]>Gets the optional value of a key path for each element in the sequence that is wrapped by anEventLoopFuture.func mapEachCompact<Result>((Value.Element) -> Result?) -> EventLoopFuture<[Result]>Calls a closure, which returns anOptional, on each element in the sequence that is wrapped by anEventLoopFuture.func mapEachFlat<ResultSegment>(KeyPath<Value.Element, ResultSegment>) -> EventLoopFuture<[ResultSegment.Element]>Gets the collection value of a key path for each element in the sequence that is wrapped by anEventLoopFuture, combining the results into a single result collection.func mapEachFlat<ResultSegment>((Value.Element) -> ResultSegment) -> EventLoopFuture<[ResultSegment.Element]>Calls a closure which returns a collection on each element in the sequence that is wrapped by anEventLoopFuture, combining the results into a single result collection.func flatMapEach(on: any EventLoop, (Value.Element) -> EventLoopFuture<Void>) -> EventLoopFuture<Void>Calls a closure, which returns anEventLoopFuture, on each element in a sequence that is wrapped by anEventLoopFuture. No results from each future are expected.func flatMapEach<Result>(on: any EventLoop, (Value.Element) -> EventLoopFuture<Result>) -> EventLoopFuture<[Result]>Calls a closure, which returns anEventLoopFuture, on each element in a sequence that is wrapped by anEventLoopFuture.func flatMapEachCompact<Result>(on: any EventLoop, (Value.Element) -> EventLoopFuture<Result?>) -> EventLoopFuture<[Result]>Calls a closure, which returns anEventLoopFuture<Optional>, on each element in a sequence that is wrapped by anEventLoopFuture.func flatMapEachThrowing<Result>((Value.Element) throws -> Result) -> EventLoopFuture<[Result]>Calls a closure on each element in the sequence that is wrapped by anEventLoopFuture.func flatMapEachCompactThrowing<Result>((Value.Element) throws -> Result?) -> EventLoopFuture<[Result]>Calls a closure, which returns anOptional, on each element in the sequence that is wrapped by anEventLoopFuture.func sequencedFlatMapEach((Value.Element) -> EventLoopFuture<Void>) -> EventLoopFuture<Void>An overload ofsequencedFlatMapEach(_:)which returns aVoidfuture instead of[Void]when the result type of the transform closure isVoid.func sequencedFlatMapEach<Result>((Value.Element) -> EventLoopFuture<Result>) -> EventLoopFuture<[Result]>A variant form offlatMapEach(on:_:)which guarantees:func sequencedFlatMapEachCompact<Result>((Value.Element) -> EventLoopFuture<Result?>) -> EventLoopFuture<[Result]>Variant ofsequencedFlatMapEach(_:)which providescompactMap()semantics by allowing result values to benil. Such results are not included in the output array.static func whenTheySucceed<A, B>(EventLoopFuture<A>, EventLoopFuture<B>, file: StaticString, line: UInt) -> EventLoopFuture<(A, B)>Returns a newEventLoopFuturethat succeeds only if all of the provided fs succeed. The newEventLoopFuturewill contain all of the values fulfilled by the fs.