3 ms·
So what is the right way to do the same thing? Use `select` and get new array included elements we want to keep instead of using `reject!`?
by tzwm 10y ago
So what is the right way to do the same thing? Use `select` and get new array included elements we want to keep instead of using `reject!`?
- pmontra 10y agoThat's what languages with immutable data structures do. Internally they implement simple data structures (lists, arrays) with more complex ones not to get a performance hit. For example, they don't want to copy every byte every time they add or remove from a list. In ascending order of complexity http://theerlangelist.blogspot.com/2013/05/working-with-immutable-data.html http://theerlangelist.blogspot.com/2013/05/working-with-immu... http://concurrencyfreaks.blogspot.com/2013/10/immutable-data-structures-are-not-as.html http://concurrencyfreaks.blogspot.com/2013/10/immutable-data... http://debasishg.blogspot.com/2010/05/grokking-functional-data-structures.html http://debasishg.blogspot.com/2010/05/grokking-functional-da... In the case of Ruby, it's a language build on mutability so let's use mutable data. There are already plenty of languages with immutable data to use if we want to.
- danaliv 10y agoThere's a non-mutating version of `reject!` called `reject`. (Likewise there's a mutating version of `select` called `select!`.)