Mathematica equivalent of Ruby's inject

Posted by Ben Alpert on Stack Overflow See other posts from Stack Overflow or by Ben Alpert
Published on 2010-06-02T23:54:32Z Indexed on 2010/06/03 0:04 UTC
Read the original article Hit count: 320

Is there a Mathematica function like inject in Ruby? For example, if I want the product of the elements in a list, in Ruby I can write:

list.inject(1) { |prod,el| prod * el }

I found I can just use Product in Mathematica:

Apply[Product, list]

However, this isn't general enough for me (like, if I don't just want the product or sum of the numbers). What's the closest equivalent to inject?

© Stack Overflow or respective owner

Related posts about functional-programming

Related posts about mathematica