[swift-evolution] Add an ifPresent function to Optional
Howard Lovatt
howard.lovatt at gmail.com
Fri Mar 11 21:17:07 CST 2016
@Dave, Yes, CollectionType would be better than SequenceType.
On Saturday, 12 March 2016, Dave via swift-evolution <
swift-evolution at swift.org> wrote:
> +1.
>
> I’d go so far as to suggest that maybe Optional should conform to
> CollectionProtocol, since you can pretty easily think of an Optional as a
> collection that can’t have more than one element.
>
> - Dave Sweeris
>
> On Mar 10, 2016, at 7:32 PM, Erica Sadun via swift-evolution <
> swift-evolution at swift.org
> <javascript:_e(%7B%7D,'cvml','swift-evolution at swift.org');>> wrote:
>
> While I'm not convinced of the utility or lack thereof, wouldn't it make
> more sense
> to extend `forEach` to support optionals in a similar way that map and
> flapMap
> currently do rather than introduce `ifPresent`?
>
> let y: Int? = 1
> let n: Int? = nil
>
> _ = y.map({ print($0) }) // works in current Swift
> _ = n.map({ print($0) }) // ditto
>
> y.forEach{ print($0) } // not currently a thing
> n.forEach{ print($0) } // ditto
>
> Just spitballing here.
>
> -- E
>
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> <javascript:_e(%7B%7D,'cvml','swift-evolution at swift.org');>
> https://lists.swift.org/mailman/listinfo/swift-evolution
>
>
>
--
-- Howard.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160312/e27ad629/attachment.html>
More information about the swift-evolution
mailing list