Skip to content
This repository has been archived by the owner on Jun 27, 2023. It is now read-only.

Commit

Permalink
Merge pull request #137 from vapor/implicit-map-return
Browse files Browse the repository at this point in the history
add implicit map/flatMap return types
  • Loading branch information
tanner0101 authored Apr 30, 2018
2 parents 71722db + f73005e commit 563c9d5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 2 additions & 0 deletions Sources/Async/Deprecated.swift
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
extension Future {
/// See `cascade(promise:)`.
@available(*, deprecated, renamed: "cascade(promise:)")
public func chain(to promise: Promise<T>) {
self.cascade(promise: promise)
}
}

extension Array where Element == Future<Void> {
/// See `flatten(on:)`.
@available(*, deprecated)
public func transform<T>(on worker: Worker, to callback: @escaping () throws -> Future<T>) -> Future<T> {
return flatten(on: worker).flatMap(to: T.self, callback)
Expand Down
6 changes: 3 additions & 3 deletions Sources/Async/Future+Map.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ extension Future {
/// print(futureInt) // Future<Int>
///
/// See `flatMap(to:_:)` for mapping `Future` results to other `Future` types.
public func map<T>(to type: T.Type, _ callback: @escaping (Expectation) throws -> T) -> Future<T> {
public func map<T>(to type: T.Type = T.self, _ callback: @escaping (Expectation) throws -> T) -> Future<T> {
let promise = eventLoop.newPromise(T.self)

self.do { expectation in
Expand Down Expand Up @@ -42,8 +42,8 @@ extension Future {
/// print(futureRes) // Future<Response>
///
/// See `map(to:_:)` for mapping `Future` results to non-`Future` types.
public func flatMap<Wrapped>(to type: Wrapped.Type, _ callback: @escaping (Expectation) throws -> Future<Wrapped>) -> Future<Wrapped> {
let promise = eventLoop.newPromise(Wrapped.self)
public func flatMap<T>(to type: T.Type = T.self, _ callback: @escaping (Expectation) throws -> Future<T>) -> Future<T> {
let promise = eventLoop.newPromise(T.self)

self.do { expectation in
do {
Expand Down

0 comments on commit 563c9d5

Please sign in to comment.