Thomvis / BrightFutures

Write great asynchronous code in Swift using futures and promises
MIT License
1.9k stars 184 forks source link

flatMap compilation error #128

Closed jc-paris closed 8 years ago

jc-paris commented 8 years ago

Hi Thomas,

I run into a strange issue with .flatMap that I don't succeed to solve. I wrote some sample code to reproduce the error:

This compile:

let future = Future<Int, Error>()
future.flatMap { i in
    return Future<String, Error>()
}

This strangely doesn't compile:

let future = Future<Int, Error>()
future.flatMap { i in
    let f = Future<String, Error>()
    return f
}

Neither does this one:

let future = Future<Int, Error>()
future.flatMap { i in
    let promise = Promise<String, Error>()
    return promise.future
}

Any explication ? Is it a BrightFutures issue or me doesn't using it right ?

Thomvis commented 8 years ago

Swift is not able to infer the type of multi-line closures. You'll need to something like this:

let future = Future<Int, Error>()
future.flatMap { i -> Future<String, Error> in
    let f = Future<String, Error>()
    return f
}
jc-paris commented 8 years ago

Oh right ! Compilation error got me wrong. It's a tricky one !