title: Using Kotlin WHEN clause for <, <=, >=, > comparisons
body: <p>I'm trying to use the <code>WHEN</code> clause with a <code>&gt;</code> or <code>&lt;</code> comparison.</p>
  
  <p>This doesn't compile. Is there a way of using the normal set of boolean operators (&lt; &lt;=, >= >) in a comparison to enable this?</p>
  
  <pre><code>val foo = 2
  
  // doesn't compile
  when (foo) {
      &gt; 0 -&gt; doSomethingWhenPositive()
      0   -&gt; doSomethingWhenZero()
      &lt; 0 -&gt; doSomethingWhenNegative()
  }
  </code></pre>
  
  <p>I tried to find an unbounded range comparison, but couldn't make this work either? Is it possible to write this as an unbounded range?</p>
  
  <pre><code>// trying to get an unbounded range - doesn't compile
  when (foo) {
      in 1.. -&gt; doSomethingWhenPositive()
      else -&gt; doSomethingElse()
  }
  </code></pre>
  
  <p>You can put the whole expression in the second part, which is OK but seems like unnecessary duplication. At least it compiles and works.</p>
  
  <pre><code>when {
      foo &gt; 0 -&gt; doSomethingWhenPositive()
      foo &lt; 0 -&gt; doSomethingWhenNegative()
      else -&gt; doSomethingWhenZero()
  }
  </code></pre>
  
  <p>But I'm not sure that is any simpler than the if-else alternative we have been doing for years. Something like:</p>
  
  <pre><code>if ( foo &gt; 0 ) {
      doSomethingWhenPositive()
  }
  else if (foo &lt; 0) {
      doSomethingWhenNegative()
  }
  else {
      doSomethingWhenZero()
  }
  </code></pre>
  
  <p>Of course, real world problems are more complex than the above, and the <code>WHEN</code> clause is attractive but doesn't work as I expect for this type of comparison.</p>