Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
def inject(l, x, &block) if l.empty? x else inject(l[1..-1], block.call(x, l.first), &block) end end
- Loading branch information
Showing
1 changed file
with
4 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5e10048
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sweet. Are there any convenient combinators that could be used to write
SUM
andPRODUCT
point-free?5e10048
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually,
SUM
andPRODUCT
are already point-free when their arguments are taken in the conventional (vs the Ruby-friendly) order; on thepedant
branch you can see how reorderingINJECT
's arguments allows you to eta-contractSUM
andPRODUCT
into point-free form.