I’ve often heard Ruby’s inject method criticized as being ‘slow.’ As I rather like the function, and see equivalents in other languages, I’m curious if it’s merely Ruby’s implementation of the method that’s slow, or if it is inherently a slow way to do things (e.g. should be avoided for non-small collections)?
Share
injectis likefold, and can be very efficient in other languages,fold_leftspecifically, since it’s tail-recursive.