Skip to content

Instance Method

flatMapEachCompact(on:_:)

Calls a closure, which returns an EventLoopFuture<Optional>, on each element in a sequence that is wrapped by an EventLoopFuture.
func flatMapEachCompact<Result>(on eventLoop: any EventLoop, _ transform: @escaping (Value.Element) -> EventLoopFuture<Result?>) -> EventLoopFuture<[Result]>

Parameters

eventLoop

The EventLoop to flatten the resulting array of futures on.

transform

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

Return Value

A new EventLoopFuture that wraps the non-nil results of all the EventLoopFutures returned from the closure.

Discussion

let users = eventLoop.future([User(name: "Tanner", ...), ...])
let pets = users.flatMapEach(on: eventLoop) { $0.favoritePet(on: database) }

See Also

EventLoopFuture