title: Swift: assign to variable in switch case-let-where
body: <p>Is it possible to make an assignment to the artist variable <strong>before</strong> it is used in the where subclause?</p>
  
  <pre><code>var artist
  switch fullline {
  case let path where path.hasPrefix("Monet"):
      artist = "Monet"
  case let path where path.hasPrefix("Cezanne"):
      artist = "Cezanne"
  default: ()
  }
  </code></pre>
  
  <p><strong>Closure:</strong></p>
  
  <pre><code>case let path where { () -&gt; Bool in let artist = "Monet"; return path.hasPrefix(artist) }:
  </code></pre>
  
  <p><strong>Error:</strong> </p>
  
  <blockquote>
    <p>() -> Bool' is not convertible to 'Bool'</p>
  </blockquote>
  
  <p><strong>Context:</strong></p>
  
  <p>I have lines of freeform text with artist name as the prefix that requires
  massaging to output consistent humanly readable text. e.g.</p>
  
  <blockquote>
  <pre><code>Monet : Snow at Argenteuil 02, 1874
  Monet - Snow at Argenteuil, 1874, 3rd Floor Collections
  Monet, Claude - 1875, Snow in Argenteuil
  Cezzane - Vase of Flowers, 1880-81, print
  Cezzane, Paul 1900-1903 Vase of Flowers
  Cezzane - Vase with Flowers, 1895-1896
  </code></pre>
  </blockquote>
  
  <p>There will be a code fragments that performs detailed processing/categorizing
  for each artist. Hence the processing logic is artist dependent.</p>
  
  <p>I would like to define similar to the following construct</p>
  
  <pre><code>switch fullline
  hasPrefix(artist = "Monet")  
      -&gt; code logic 1
         get_birthday(artist)
  
  hasPrefix(artist = "Cezzane")
      -&gt; code logic 2
         get_birthday(artist)
  </code></pre>