Skip to content

Instance Method

mapEach(_:)

Calls a closure on each element in the sequence that is wrapped by an EventLoopFuture.
func mapEach<Result>(_ transform: @escaping (Value.Element) -> 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([1, 2, 3, 4, 5, 6, 7, 8, 9])
let times2 = collection.mapEach { int in
    return int * 2
}
// times2: EventLoopFuture([2, 4, 6, 8, 10, 12, 14, 16, 18])

See Also

EventLoopFuture