News for hackers. Stuff that matters.
Re:Effective Scala by auggierose on Thursday September 05, 2013 @01:19PM (#6335443)
There is no performance difference here, map etc. are producing the same garbage. Scala isn't Haskell. Also note that there is a HUGE performance difference between appending and prepeding to a list. :-)
Re:Effective Scala by mark242 on Thursday September 05, 2013 @02:17PM (#6335844)
I don't think that's right.

TraversableLike, and FilterMonadic will both size up the resulting return value based upon the length of what's passed to it. You'll get a List of N items, and the call to flatMap will also traverse the list to remove/flatten the Options. Items will then get dropped in the List. You're looking at one or two collectable objects every time you run through that method, as opposed to bin.items.length collectable objects in your original code.

Look at it this way-- what happens if bin.items is a List() of 10M objects? completed_items can be replaced up to 10M times. The .flatMap creates one collection of 10M length, removes the None objects, and returns the resulting List.

Re:Effective Scala by GyrosOfWar on Thursday September 05, 2013 @01:54PM (#6335689)
> Also note that there is a HUGE performance difference between appending and prepeding to a list. :-)

If you're going to do a lot of appending, might I suggest a ListBuffer or a Vector?

Re:Effective Scala by bad_user on Thursday September 05, 2013 @01:48PM (#6335640)
If you need to append, use a Vector instead.