<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Immutability on Andrew Bancroft</title>
    <link>https://www.andrewcbancroft.com/tags/immutability/</link>
    <description>Recent content about iOS development with Swift in Immutability  from Andrew Bancroft.</description>
    <generator>Hugo -- gohugo.io</generator>
    <language>en-us</language>
    <lastBuildDate>Tue, 20 Jan 2015 12:30:51 +0000</lastBuildDate>
    
        <atom:link href="https://www.andrewcbancroft.com/tags/immutability/index.xml" rel="self" type="application/rss+xml" />
    
    
    <item>
      <title>Conveniently Transforming Immutable Types in Swift</title>
      <link>https://www.andrewcbancroft.com/2015/01/20/conveniently-transforming-immutable-types-swift/</link>
      <pubDate>Tue, 20 Jan 2015 12:30:51 +0000</pubDate>
      
      <guid>https://www.andrewcbancroft.com/2015/01/20/conveniently-transforming-immutable-types-swift/</guid>
      <description>&lt;p&gt;A few weeks ago I wrote about &lt;a href=&#34;http://www.andrewcbancroft.com/2015/01/06/immutable-types-changing-state-swift/&#34;&gt;Immutable Types and Changing State in Swift&lt;/a&gt;, where I hoped to convey an &amp;ldquo;aha!-moment” that happened for me.&lt;/p&gt;
&lt;p&gt;Since then, I&amp;rsquo;ve learned a bit more. For example, the technique I presented for transforming instances of a Type immutably actually come for free when you use a value Type, such as a Struct! Check out &lt;a href=&#34;https://twitter.com/NatashaTheRobot&#34;&gt;@NatashaTheRobot&amp;rsquo;s&lt;/a&gt; writeup on the subject, titled &lt;a href=&#34;http://natashatherobot.com/mutating-functions-swift-structs/&#34;&gt;&amp;ldquo;Mutating Functions in Swift Structs”&lt;/a&gt;, for more information.&lt;/p&gt;
&lt;p&gt;But let&amp;rsquo;s say, for whatever reason, you&amp;rsquo;d like to use a &lt;em&gt;reference&lt;/em&gt; Type, such as a Class. In that case, the technique I presented in the aforementioned blog entry works out quite nicely. &lt;em&gt;Until….&lt;/em&gt;&lt;/p&gt;
&lt;h3 id=&#34;many-init-parameters--pain&#34;&gt;Many init parameters == Pain&lt;/h3&gt;
&lt;p&gt;… It works great right up until you have more than a few immutable properties that you need to transform.&lt;/p&gt;
&lt;p&gt;I want to thank &lt;a href=&#34;https://twitter.com/Jarsen&#34;&gt;@Jarsen&lt;/a&gt; for his &lt;a href=&#34;http://www.andrewcbancroft.com/2015/01/06/immutable-types-changing-state-swift/#comment-1788688298&#34;&gt;comment&lt;/a&gt;. He pointed out the exact pain point I was feeling, since I was actually using my own advice in a personal project. Not only that, he offers a solution in the form of a &lt;a href=&#34;https://gist.github.com/jarsen/41de7401d49cd2348e5f&#34;&gt;GitHub gist&lt;/a&gt;!&lt;/p&gt;
&lt;p&gt;I&amp;rsquo;m bringing in his example so that we have it before us with a few minor modifications to make it relevant for this blog entry. However, I want to give 100% credit to Jarsen for his insight.&lt;/p&gt;
&lt;h3 id=&#34;its-all-about-convenience&#34;&gt;It&amp;rsquo;s all about convenience&lt;/h3&gt;
&lt;p&gt;The gist of Jarsen&amp;rsquo;s solution was to create a second helper initializer which would help setting the values for all the properties easier. Take a look:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-swift&#34; data-lang=&#34;swift&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt; 1&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;kd&#34;&gt;class&lt;/span&gt; &lt;span class=&#34;nc&#34;&gt;Scorekeeper&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt; 2&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;kd&#34;&gt;let&lt;/span&gt; &lt;span class=&#34;nv&#34;&gt;runningScore&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt; &lt;span class=&#34;nb&#34;&gt;Int&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt; 3&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;kd&#34;&gt;let&lt;/span&gt; &lt;span class=&#34;nv&#34;&gt;climbingScore&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt; &lt;span class=&#34;nb&#34;&gt;Int&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt; 4&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;c1&#34;&gt;// potentially more properties&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt; 5&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;    
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt; 6&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;kd&#34;&gt;init&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;runningScore&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt; &lt;span class=&#34;nb&#34;&gt;Int&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;0&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;climbingScore&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt; &lt;span class=&#34;nb&#34;&gt;Int&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;0&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt; 7&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;        &lt;span class=&#34;kc&#34;&gt;self&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;runningScore&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;runningScore&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt; 8&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;        &lt;span class=&#34;kc&#34;&gt;self&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;climbingScore&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;climbingScore&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt; 9&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;p&#34;&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt;10&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;    
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt;11&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;c1&#34;&gt;// second helper initializer&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt;12&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;kd&#34;&gt;init&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;scoreKeeper&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;Scorekeeper&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;runningScore&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt; &lt;span class=&#34;nb&#34;&gt;Int&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;?&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;kc&#34;&gt;nil&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;climbingScore&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt; &lt;span class=&#34;nb&#34;&gt;Int&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;?&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;kc&#34;&gt;nil&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt;13&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;        &lt;span class=&#34;kc&#34;&gt;self&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;runningScore&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;runningScore&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;??&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;scoreKeeper&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;runningScore&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt;14&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;        &lt;span class=&#34;kc&#34;&gt;self&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;climbingScore&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;climbingScore&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;??&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;scoreKeeper&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;climbingScore&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt;15&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;p&#34;&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt;16&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;    
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt;17&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;kd&#34;&gt;func&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;incrementRunningScoreBy&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;points&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt; &lt;span class=&#34;nb&#34;&gt;Int&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;Scorekeeper&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt;18&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;        &lt;span class=&#34;k&#34;&gt;return&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;Scorekeeper&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;scoreKeeper&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt; &lt;span class=&#34;kc&#34;&gt;self&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;runningScore&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt; &lt;span class=&#34;kc&#34;&gt;self&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;runningScore&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;+&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;points&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt;19&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;p&#34;&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt;20&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;    
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt;21&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;c1&#34;&gt;// other functions to transform Scorekeeper by incrementing other score properties&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt;22&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;p&#34;&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Note the use of optionals, and the corresponding nil-coalescing operator (&lt;code&gt;??&lt;/code&gt;) in the helper initializer&amp;rsquo;s implementation. It&amp;rsquo;s simple, &lt;em&gt;and&lt;/em&gt; it&amp;rsquo;s concise. I like it!&lt;/p&gt;
&lt;p&gt;The bottom line is that I couldn&amp;rsquo;t help but share Jarsen&amp;rsquo;s tip. I thought it deserved a little more attention than to be stuck down in the comment section where folks may or may not find it and be helped.&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>Immutable Types with Changing State in Swift</title>
      <link>https://www.andrewcbancroft.com/2015/01/06/immutable-types-changing-state-swift/</link>
      <pubDate>Tue, 06 Jan 2015 12:00:50 +0000</pubDate>
      
      <guid>https://www.andrewcbancroft.com/2015/01/06/immutable-types-changing-state-swift/</guid>
      <description>&lt;p&gt;Dabble in Swift for long and the functional programming paradigm will most certainly appear on your radar. From conferences to books to blog posts, I&amp;rsquo;ve seen a lot in the functional programming arena as it relates to Swift.&lt;/p&gt;
&lt;p&gt;As I seek to improve my functional programming thought processes and to practice what I&amp;rsquo;m learning, I found myself struggling with a fundamental concept: &lt;strong&gt;immutability&lt;/strong&gt;. &lt;em&gt;Especially&lt;/em&gt; when I&amp;rsquo;m designing something that, at the very least, &lt;em&gt;appears&lt;/em&gt; to require the ability to change state at some point in time.&lt;/p&gt;
&lt;h3 id=&#34;immutable-changes--a-contradiction-in-terms&#34;&gt;Immutable changes – A contradiction in terms?&lt;/h3&gt;
&lt;p&gt;Immutability and changing state was a real struggle for me. The two seemed contradictory actually. How am I supposed to handle changes with things that &lt;em&gt;can&amp;rsquo;t change&lt;/em&gt;??!&lt;/p&gt;
&lt;p&gt;And then, with the help of Stack Overflow, a lightbulb came on. As I was perusing FP topics, I ran across a question that expressed exactly what I was feeling. &lt;a href=&#34;http://stackoverflow.com/questions/1020653/how-can-you-do-anything-useful-without-mutable-state&#34;&gt;&amp;ldquo;How can you do anything useful without mutable state?”&lt;/a&gt;, the questioner asked. The answer is what illuminated things for me. The key quote from the Stack Overflow answer:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;In functional languages, rather than mutating the state of objects, we simply return a new object with the changes we want.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;So… instead of thinking about state changes as &lt;em&gt;mutations&lt;/em&gt;, think of them as reasons to create something &lt;em&gt;new&lt;/em&gt;.&lt;/p&gt;
&lt;h3 id=&#34;getting-practical-with-swift&#34;&gt;Getting practical with Swift&lt;/h3&gt;
&lt;p&gt;If I&amp;rsquo;m going to get pragmatic with this, I have some design decisions to make if I&amp;rsquo;m going to try and avoid mutating the state of my objects. Rather than design my Types with the intent to update stored properties in-place, I should think about designing them so that the state-change process would actually produce a whole &lt;em&gt;new&lt;/em&gt; instance with the transformed (updated) value.&lt;/p&gt;
&lt;h3 id=&#34;see-it-in-action&#34;&gt;See it in action&lt;/h3&gt;
&lt;p&gt;I&amp;rsquo;m a visual person, so for those of you who need to see it in action like me, here&amp;rsquo;s a short example: Suppose that you&amp;rsquo;re designing a class that stores a counter (or a score or a total… something like that), and provides a function to let you increment that count.&lt;/p&gt;
&lt;h3 id=&#34;the-mutating-way&#34;&gt;The mutating way&lt;/h3&gt;
&lt;p&gt;We could design this class in one of two ways: declare a variable stored property to hold the count. The method would then reassign incremented values to it. This is the &lt;em&gt;opposite&lt;/em&gt; of immutable changes:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;class Scorekeeper {
    var runningScore: Int
    
    init (score: Int = 0) {
        self.runningScore = score
    }
    
    func incrementScoreBy(points: Int) {
        runningScore += points
    }
}

let scoreKeeper = Scorekeeper()
scoreKeeper.incrementScoreBy(5)
println(scoreKeeper.runningScore)
// prints 5
&lt;/code&gt;&lt;/pre&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;    &amp;lt;p&amp;gt;&amp;lt;/p&amp;gt;
    
    
    ### The immutable way
    
    
    OR, rather than mutating the existing variable, we could go an alternate route:  The second way to design the class is to declare a constant stored property.  The method would then produce _new_ instance that stored the new state:
    
    
        class Scorekeeper {
            let runningScore: Int
            
            init (score: Int = 0) {
                self.runningScore = score
            }
            
            func incrementScoreBy(points: Int) -&amp;gt; Scorekeeper {
                return Scorekeeper(score: self.runningScore + points)
            }
        }
        
        let scorekeeper = Scorekeeper()
        let scorekeeperWithIncreasedScore = scorekeeper.incrementScoreBy(5)
        println(scorekeeperWithIncreasedScore.runningScore)
        // prints 5
        
&lt;/code&gt;&lt;/pre&gt;&lt;pre&gt;&lt;code&gt;    &amp;lt;p&amp;gt;&amp;lt;/p&amp;gt;
    
    
    ### Observations
    
    
    As I look at the code I&#39;ve just presented, I notice a few things as I contrast the two examples:
    
    
    
    
    
      * The first example uses var to declare the stored property of my Scorekeeper class.  It _has_ to be var so that the value of the property can be changed (mutated).
    
    
      * The second example uses let exclusively.  No in-place mutations occur, so constants are perfectly reasonable to use.
    
    
    
    * * *
    
    
    
    
    
      * The first example&#39;s design lends itself to produce interesting and unpredictable side-effects.  If multiple clients hold a reference to my scorekeeper instance, there are two ways for the runningScore to change out from underneath any of those clients:  First, I could simply reassign a value to the runningScore directly.  Second, I could call incrementScoreBy().  Either way, unintended consequences may arise because of the mutation.
    
    
      * In the second example, it&#39;s _impossible_ to cause those unintended consequences.  runningScore can&#39;t be changed directly (it&#39;s a constant), and incrementScoreBy() returns a whole _new_ instance, so all clients would be dealing with the instance that they expect to be dealing with.  No values can be changed out from underneath them.
    
    
    
    * * *
    
    
    
    
    
      * The first example&#39;s incrementScoreBy method has no return value.  While I can envision writing a unit test for this, it&#39;s not obvious at first glance what I should do.  The method produces a side-effect in my existing instance that I need to know about in order to get the XCTAssert right.
    
    
      * The second example&#39;s incrementScoreBy method returns a new Scorekeeper instance.  The unit test for this (to me) is a little more clear.  I simply inspect the value of runningScore of the new instance, and assert that it is [x] points higher than the old instance.  I still have both the old scorekeeper instance _and_ the new scorekeeperWithIncreasedScore, so everything I&#39;d need to ensure the correct point increase occurred is at my disposal.
    
    
    
    ### Conclusion
    
    
    I hear so much benefit that comes from avoiding mutable state, so it was satisfying to finally let my mind reconcile how to manage the state of my own Types immutably.  With the iOS frameworks we have to work with, immutability is a challenge, and _total_ immutable state is not possible (think of the user interface layer where state is stored and updated out of necessity because of how _Apple&#39;s_ frameworks and tools are designed). Nonetheless, I found this discovery to be really exciting all the same.
&lt;/code&gt;&lt;/pre&gt;
</description>
    </item>
    
  </channel>
</rss>