title: Providing default instance arguments for (recursive) extension in Swift
body: <p>I was having fun while practicing a Kata.<br>
  I wanted to implement one of the <strong>functions</strong> in my solution <strong>as</strong> an <strong>extension</strong> of <code>Int</code>, because I liked the idea of having pretty syntax. The function, in itself, looks like this:</p>
  <pre><code>func decomposed(_ n: Int) -&gt; [Int] {
      if n &gt; 10 {
        return n.decomposed(n / 10) + [n % 10] 
      } else {
        return [n]
      }
    }
  </code></pre>
  <p>Now, I've tried to implement it as an <strong>extension</strong>. Due to the fact that I would like to use it like <code>420.decomposed()</code>, I figured that I would need the <strong>instance</strong> as the <strong>default argument</strong>. I proceeded with:</p>
  <pre><code>extension Int {
    func decomposed(_ n: Int = self) -&gt; [Int] {
      if n &gt; 10 {
        return n.decomposed(n / 10) + [n % 10] 
      } else {
        return [n]
      }
    }
  }
  </code></pre>
  <p>This is the part, however, in which it gets trickier. I'm being told by the compiler that <code>error: cannot find 'self' in scope</code>.<br></p>
  <p>Having read about the methods <a href="https://docs.swift.org/swift-book/LanguageGuide/Extensions.html#ID154" rel="nofollow noreferrer">in the docs</a>, I've resorted to using <code>Int?</code> default argument. Now, the extension is implemented as:</p>
  <pre><code>extension Int {
    func decomposed(_ n: Int? = nil) -&gt; [Int] {
      var _n = n ?? self
      if _n &gt; 10 {
        return _n.decomposed(_n / 10) + [_n % 10] 
      } else {
        return [_n]
      }
    }
  }
  </code></pre>
  <p>I don't like the look of the <code>_n</code>, though.<br>
  <strong>I would love to use self as the default argument.</strong> Is that possible? Or are we stuck with hackity hacks until the judgement day?</p>