title: scala iterating through the set type with condition
body: <p>I have a type of set and union function as follow</p>
  
  <pre><code>type Set = Int =&gt; Boolean
  def union(s: Set, t: Set): Set = (e: Int) =&gt; s(e) || t(e)
  val xs = Set(12001,12002, 12003, 12004)
  val ys = Set(13001,13002, 13003, 13004)
  </code></pre>
  
  <p>When i use the union operation,</p>
  
  <pre><code>union(xs,ys)
  </code></pre>
  
  <p>It should return me another set which contains all the elements of both sets <code>xs</code> and <code>ys</code></p>
  
  <blockquote>
    <p>Edited Section:</p>
  </blockquote>
  
  <p>I am sorry i was not clear on my question, i have my own implementation of the iterator for both Set xs and ys</p>
  
  <pre><code>var i = xs.iterator;
  while(i.hasNext)
    println(i.next())
  </code></pre>
  
  <p>But i was not satisfied with this implementation and found that you can implement the condition with the function (after some googling) but i was unable to get it to work in my eclipse worksheet. </p>
  
  <pre><code>val rs = union(xs,ys)            //&gt; rs  : Learn2.Set = &lt;function1&gt;
  </code></pre>
  
  <p>I am guessing it returns a function. </p>
  
  <p>so my questions,
  1. is it possible to implement as described above in the edited section? if so, then what am i missing to get it working?
  2. I don't understand how the element <code>e</code> in <code>(e: Int) =&gt; s(e) || t(e)</code> is iterating over the elements in both the sets </p>