3 ms·
Very good post. One point with which i cannot agree is "In fact, it is impossible to insert a new method that behaves like a normal collection method. " Please
by OlegYch 15y ago
Very good post.
One point with which i cannot agree is "In fact, it is impossible to insert a new method that behaves like a normal collection method. "
Please see http://ideone.com/ePUHG http://ideone.com/ePUHG
An excerpt:
import MyEnhancements._
println("qwe".quickSort)
println(Array(2,0).quickSort)
println(Seq(2,0).quickSort)
- etorreborre 15y agoMiles Sabin's solution is also worth a look: https://gist.github.com/f83892f65f63b14a1f75 https://gist.github.com/f83892f65f63b14a1f75 It uses dependent types which will be included by default in Scala 2.10. I don't consider this as "simple" but my point of view is that Computer Science is not "simple" :-). And having a language supporting that level of genericity is really helpful for type-safety and code reuse.
- milessabin 15y ago@OlegYch's solution also represents a good trade off of complexity vs. convenience: his solution is simpler but doesn't get along so nicely with type inference; mine gets on just fine with type inference, but is more complex and depends (no pun intended) on dependent method types. As ever YMMV.