Instance Method
optionalFlatMap(_:)
Calls a closure on an optional value in an
EventLoopFuture if it exists.func optionalFlatMap<Wrapped, Result>(_ closure: @escaping (Wrapped) -> EventLoopFuture<Result>) -> EventLoopFuture<Result?> where Value == Wrapped?
Parameters
closureThe closure to call on the unwrapped optional value.
Return Value
The result of the closure if the optional was unwrapped, or nil if it wasn’t, wrapped in an EventLoopFuture.
Discussion
let optional = eventLoop.future(Optiona<Int>.some(42))
let some = optional.optionalFlatMap { int -> EventLoopFuture<Float> in
return int * 3.14
}
// some: EventLoopFuture(Optional(131.88))
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>(KeyPath<Value.Element, Result>) -> EventLoopFuture<[Result]>Gets the value of a key path for each element in the sequence that is wrapped by anEventLoopFuture.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.