Ok, I see. However this could be a potential source of bugs/performance issues 
where you don't consider the nil case and you do some unnecessary work. By 
prohibiting to pass nil you have to manually unwrap and you immediately see the 
"optionality".

> Am 15.08.2016 um 22:36 schrieb Tim Vermeulen <tvermeu...@me.com>:
> 
> Oh, that’s true, I misunderstood your previous message. It’s not about 
> passing nil, but it’s about passing optionals. The point is to be able to do 
> something like this:
> 
> let number = functionThatReturnsAnOptional()
> sequence(first: number, next: { $0 % 2 == 0 ? $0 / 2 : nil })
> 
>> On 15 Aug 2016, at 22:26, Maximilian Hünenberger <m.huenenber...@me.com> 
>> wrote:
>> 
>> Probably I didn't understand your proposal. What do you want to change 
>> exactly?
>> 
>> I thought:
>> public func sequence<T>(first: T, next: @escaping (T) -> T?) -> 
>> UnfoldFirstSequence<T> { ... }
>> 
>> To:
>> public func sequence<T>(first: T?, next: @escaping (T) -> T?) -> 
>> UnfoldFirstSequence<T> { ... }
>> 
>>> Am 15.08.2016 um 22:17 schrieb Tim Vermeulen <tvermeu...@me.com>:
>>> 
>>> You can’t; the `first` parameter has type `T`, not `T?`.
>>> 
>>>> On 15 Aug 2016, at 22:10, Maximilian Hünenberger <m.huenenber...@me.com> 
>>>> wrote:
>>>> 
>>>> Hi Tim,
>>>> 
>>>> If you pass "nil" to "first" isn't this an empty sequence? So it would be 
>>>> redundant.
>>>> 
>>>> Best regards
>>>> Maximilian
>>>> 
>>>>> Am 15.08.2016 um 01:27 schrieb Tim Vermeulen via swift-evolution 
>>>>> <swift-evolution@swift.org>:
>>>>> 
>>>>> sequence(first:next:) takes a non-optional first argument. Is there a 
>>>>> reason for that? sequence(state:next:) allows empty sequences, and I 
>>>>> don’t see why sequence(first:next:) shouldn’t. The fix would be to simply 
>>>>> add the `?` in the function signature; no other changes are required to 
>>>>> make it work.
>>>>> 
>>>>> I considered just filing a bug report, but since this is a change of the 
>>>>> public API...
>>>>> _______________________________________________
>>>>> swift-evolution mailing list
>>>>> swift-evolution@swift.org
>>>>> https://lists.swift.org/mailman/listinfo/swift-evolution
> 
_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

Reply via email to