masak / alma

ALgoloid with MAcros -- a language with Algol-family syntax where macros take center stage
Artistic License 2.0
139 stars 15 forks source link

Have a 'reduce' method on Array #527

Open masak opened 5 years ago

masak commented 5 years ago

(Filed while staring at #176.)

I like the way it works in JavaScript. Specifically, you need to either provide an "initial value", or make sure the list is nonempty. If you do neither of those, you get an error.

That's nice because it means something like [].reduce(infix:<min>) will just outright fail. (We can't exactly return inf there because, by #517, our infinities are syntactic.)

With things like [].reduce(infix:<+>) I guess we could ask the infix:<+> nicely if it has a "zero value". But that's beyond the scope of this issue.