Skip to content

Instance Method

optionalMap(_:)

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

Parameters

closure

The closure function that the optional value will be passed into.

Return Value

The result of the closure passed into the method (or nil), wrapped in an EventLoopFuture.

Discussion

let optional = eventLoop.future(Optional<Int>.some(42))
let some = optional.optionalMap { int -> Float in
    return int * 3.14
}
// some: EventLoopFuture(Optional(131.88))

See Also

EventLoopFuture