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
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
This is definitely neater since Oderski, despite discourages the variables, prefers this approach in TweetTest.asSet
Google/Apple tweets can also be refactored