Skip to content

Instance Method

optionalFlatMapThrowing(_:)

Calls a throwing closure on an optional value in an EventLoopFuture if it exists.
func optionalFlatMapThrowing<Wrapped, Result>(_ closure: @escaping (Wrapped) throws -> Result?) -> EventLoopFuture<Result?> where Value == Wrapped?

Parameters

closure

The 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(Optional<Int>.some(42))
let some = optional.optionalFlatMapThrowing { int -> Float in
    return int * 3.14
}
// some: EventLoopFuture(Optional(131.88))

See Also

EventLoopFuture