Skip to content

Instance Method

flatMapEachThrowing(_:)

Calls a closure on each element in the sequence that is wrapped by an EventLoopFuture.
func flatMapEachThrowing<Result>(_ transform: @escaping (Value.Element) throws -> Result) -> EventLoopFuture<[Result]>

Parameters

transform

The closure that each element in the sequence is passed into.

Return Value

A new EventLoopFuture that wraps the sequence of transformed elements.

Discussion

let collection = eventLoop.future([1, 2, 3, 4, 5, 6, 7, 8, 9])
let times2 = collection.flatMapEachThrowing { int in
    guard int < 10 else { throw RangeError.oops }
    return int * 2
}
// times2: EventLoopFuture([2, 4, 6, 8, 10, 12, 14, 16, 18])

If your callback function throws, the returned EventLoopFuture will error.

See Also

EventLoopFuture