Joined June 2014
·

Valentin Tihhomirov

tallinn
·
·

Posted to Scala week 3 over 1 year ago

The union is indeed uttermost elegance and it should be faster because it appends to the existing tree, whereas Odersky-demonstrated decomposition-based method starts appending to the left or right part of the tree, which is smaller.

Other procedures, howvever could be de-bulkanized, by using variable accumulators + foreach

def filterAcc(p: Tweet => Boolean, acc: TweetSet): TweetSet = {
  var res = acc
  foreach(t => if (p(t)) res = res incl t)
  res
}
def mostRetweeted: Tweet = {
  var most: Tweet = elem
  (left union right).foreach(t => if (t.retweets > most.retweets) most = t)
  most
}

This is definitely neater since Oderski, despite discourages the variables, prefers this approach in TweetTest.asSet

Google/Apple tweets can also be refactored

def companyTweets(l: List[String]) = TweetReader.allTweets filter (t => l.exists(k => t.text.contains(k)))
lazy val googleTweets: TweetSet = companyTweets(google)
lazy val appleTweets: TweetSet = companyTweets(apple)
Achievements
1 Karma
0 Total ProTip Views