title: Implementing map for an intensionally-defined set in Scala
body: <pre><code>  type Set = Int =&gt; Boolean
  
    /**
     * Returns whether all bounded integers within `s` satisfy `p`.
     */
    def forall(s: Set, p: Int =&gt; Boolean): Boolean = {
      def iter(a: Int): Boolean = {
        if (a &gt; bound) true
        else if (contains(s, a) &amp;&amp; !p(a)) false
        else iter(a + 1)
      }
      iter(-bound)
    }
  
    /**
     * Returns whether there exists a bounded integer within `s`
     * that satisfies `p`.
     */
    def exists(s: Set, p: Int =&gt; Boolean): Boolean = !forall(s, (x =&gt; !p(x)))
  
    /**
     * Returns a set transformed by applying `f` to each element of `s`.
     */
    def map(s: Set, f: Int =&gt; Int): Set =  (x =&gt; exists(s, (y: Int) =&gt; f(y) ==
  x))
  </code></pre>
  
  <p>so for this piece of code. I don't understand function <code>map</code>.</p>
  
  <p>I see its input are 2 arguments, which are set and method f. But the "body" part, I tried so hard but still don't get it. And what is that <code>"y"</code>, and why using f(y) == x makes it apply method f to set elemtns?</p>
  
  <p>need some explanation for me.
  thank you!</p>