<div dir="ltr"><div class="gmail_default" style="font-family:georgia,serif">That is because for `Optional` the `flatMap` is `func flatMap<U>(_ transform: (Wrapped) throws -> U?) rethrows -> U?` and for `Int`, only `init?(exactly value: Double)` fits the situation. `init(_ value: Double)` doesn't return nil. So there is no <span style="font-size:12.800000190734863px;font-family:arial,sans-serif">ambiguity.</span></div><div class="gmail_default" style="font-family:georgia,serif"><span style="font-size:12.800000190734863px;font-family:arial,sans-serif"><br></span></div><div class="gmail_default" style="font-family:georgia,serif"><span style="font-size:12.800000190734863px;font-family:arial,sans-serif">Zhaoxin</span></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, May 2, 2017 at 4:20 AM, Saagar Jha <span dir="ltr"><<a href="mailto:saagar@saagarjha.com" target="_blank">saagar@saagarjha.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word">Well, the question still remains about why the compiler chose init(exactly:) over init(). Shouldn’t there at least a warning of ambiguity?<div><span class="HOEnZb"><font color="#888888"><br><div>
<div style="color:rgb(0,0,0);letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;word-wrap:break-word">Saagar Jha</div>
</div></font></span><div><div class="h5">
<br><div><blockquote type="cite"><div>On May 1, 2017, at 12:11, Zhao Xin via swift-users <<a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a>> wrote:</div><br class="m_-6639634497264444740Apple-interchange-newline"><div><div dir="ltr"><div class="gmail_default"><font face="georgia, serif">In my test, compiler thought you use `</font><span class="m_-6639634497264444740gmail-syntax-keyword" style="font-family:arial,sans-serif;font-size:11px;white-space:pre-wrap">init</span><span style="font-family:arial,sans-serif;font-size:11px;white-space:pre-wrap">?(</span><span class="m_-6639634497264444740gmail-syntax-identifier" style="font-family:arial,sans-serif;font-size:11px;white-space:pre-wrap">exactly</span><span style="font-family:arial,sans-serif;font-size:11px;white-space:pre-wrap"> </span><span class="m_-6639634497264444740gmail-syntax-param-name" style="font-family:arial,sans-serif;font-size:11px;white-space:pre-wrap">value</span><span style="font-family:arial,sans-serif;font-size:11px;white-space:pre-wrap">: </span><span class="m_-6639634497264444740gmail-syntax-type" style="font-family:arial,sans-serif;font-size:11px;white-space:pre-wrap"><a style="color:rgb(0,51,102);text-decoration:none">Double</a></span><span style="font-family:arial,sans-serif;font-size:11px;white-space:pre-wrap">)`, </span><span style="white-space:pre-wrap"><font face="georgia, serif">which returns nil. So this is not a bug.</font></span></div><div class="gmail_default" style="font-family:georgia,serif"><span style="font-size:11px;white-space:pre-wrap;font-family:arial,sans-serif"><br></span></div><div class="gmail_default"><span style="white-space:pre-wrap"><font face="georgia, serif">Zhaoxin</font></span></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, May 2, 2017 at 1:39 AM, Halen Wooten via swift-users <span dir="ltr"><<a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi,<br>
<br>
I'm seeing a weird issue with using an initializer in flatMap. Here's<br>
an example:<br>
<br>
```<br>
let time: TimeInterval? = 662.82582598600004<br>
let intTimeFlatmap = time.flatMap(Int.init) // nil<br>
let intTime = Int(time!) // 662<br>
```<br>
<br>
I would expect for the flatMap call to return an optional Int with the<br>
proper value of 662. Is there something I'm misunderstanding, or is<br>
this a swift bug?<br>
<br>
Thanks,<br>
Halen<br>
______________________________<wbr>_________________<br>
swift-users mailing list<br>
<a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-users" rel="noreferrer" target="_blank">https://lists.swift.org/mailma<wbr>n/listinfo/swift-users</a><br>
</blockquote></div><br></div>
______________________________<wbr>_________________<br>swift-users mailing list<br><a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a><br><a href="https://lists.swift.org/mailman/listinfo/swift-users" target="_blank">https://lists.swift.org/<wbr>mailman/listinfo/swift-users</a><br></div></blockquote></div><br></div></div></div></div></blockquote></div><br></div>