title: Coursera Scala week 3 filter method not working
body: <p>I am doing coursera scala course, working on week 3 assignment. I have completed half of the functions. Stuck with filter method. I do not want an answer, what I want is understanding or hint of what I am missing. </p>
  
  <p>Here is the requirement: </p>
  
  <p>/**
      * This method takes a predicate and returns a subset of all the elements
      * in the original set for which the predicate is true.
      */</p>
  
  <pre><code>def filter(p: Tweet =&gt; Boolean): TweetSet = ???
  </code></pre>
  
  <p>Here is my code: </p>
  
  <pre><code>override def filter(p: Tweet =&gt; Boolean): TweetSet =  filterAcc(p, new Empty)
  
   def filterAcc(p: Tweet =&gt; Boolean, acc: TweetSet): TweetSet = {
    if(this.isEmpty)
      acc
    else if (p ( elem)) {
      left.filterAcc(p, acc incl elem)
      right.filterAcc(p, acc incl elem)
    }
    else
    {
      left.filterAcc(p, acc )
      right.filterAcc(p, acc )
    }
  </code></pre>
  
  <p><strong>Update</strong>:  Adding some more context to this problem. Here is the base class: </p>
  
  <pre><code>abstract class TweetSet {
  
  def filter(p: Tweet =&gt; Boolean): TweetSet = ???
  
  def filterAcc(p: Tweet =&gt; Boolean, acc: TweetSet): TweetSet
  
  def union(that: TweetSet): TweetSet = ???
  
  def isEmpty: Boolean = ???
  
  def incl(tweet: Tweet): TweetSet
  
  def contains(tweet: Tweet): Boolean
  
  }
  </code></pre>
  
  <p>I have two implementations Empty and NonEmpty representing sets with and without any elements.</p>
  
  <p>Test Case: </p>
  
  <pre><code>val set1 = new Empty
  val set2 = set1.incl(new Tweet("a", "a body", 20))
  val set3 = set2.incl(new Tweet("b", "b body", 20))
  val c = new Tweet("c", "c body", 7)
  val d = new Tweet("d", "d body", 9)
  val set4c = set3.incl(c)
  val set4d = set3.incl(d)
  val set5 = set4c.incl(d)  
  
  test("filter: a on set5") {
   new TestSets {
   assert(size(set5.filter(tw =&gt; tw.user == "a")) === 1) // this fails
   }
  }
  </code></pre>
  
  <p>Result: </p>
  
  <p>[info] - filter: a on set5 <strong>* FAILED *</strong>
  [info]   0 did not equal 1 (TweetSetSuite.scala:64)</p>