Created
January 12, 2018 01:21
-
-
Save felipec/811711cb4dbddbf1b9def5065d894078 to your computer and use it in GitHub Desktop.
Simple scanl implementation
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
class Array | |
def scanl(init) | |
self.reduce([init]) { |a, e| a.push(yield(a.last, e)) } | |
end | |
end | |
accum = [5, 10, 15].scanl(0) { |a, b| a + b }[1..-1] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment