[swift-evolution] SE-0023 API Design Guidelines: Mutating vs Functional
Erica Sadun
erica at ericasadun.com
Mon Jan 25 15:22:05 CST 2016
I incorporated your feedback. Please reload: https://github.com/erica/SwiftStyle/blob/master/Grammatical.md
-- E
> On Jan 25, 2016, at 2:52 AM, Haravikk <swift-evolution at haravikk.com> wrote:
>
>
>> On 25 Jan 2016, at 06:12, T.J. Usiyan via swift-evolution <swift-evolution at swift.org> wrote:
>>
>> 'Functional' is pretty vague in this context. Mutating cuts to differentiating trait.
>>
>> "A function produces something" can fall down if I have a function with side effects.
>>
>> ``` swift
>> private var state = 0
>> func generateCount() -> String {
>> state += 1
>> return "I've been called \(state) times"
>> }
>> ```
>>
>> We could narrow it by saying that a pure function has no side effects but this just draws us further from the relevant point, in my opinion.
>> _______________________________________________
>> swift-evolution mailing list
>> swift-evolution at swift.org
>> https://lists.swift.org/mailman/listinfo/swift-evolution
>
> Also, how do we differentiate between functions that have @warn_unused_result? In your example the string that’s returned isn’t actually required to be used, so someone could call the function purely with the intention of increment state; not that it would be a very useful thing to do, but some functions have return values that aren’t necessarily required, like removeLast() on Arrays (I may not actually want the last array element, or I already know what it is and just want it removed).
More information about the swift-evolution
mailing list