Skip to content

Instance Method

flatMapEachCompactThrowing(_:)

Calls a closure, which returns an Optional, on each element in the sequence that is wrapped by an EventLoopFuture.
func flatMapEachCompactThrowing<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(["one", "2", "3", "4", "five", "^", "7"])
let times2 = collection.mapEachCompact { int in
    return Int(int)
}
// times2: EventLoopFuture([2, 3, 4, 7])

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

See Also

EventLoopFuture