Skip to content

Instantly share code, notes, and snippets.

@felipec
Created January 12, 2018 01:21
Show Gist options
  • Save felipec/811711cb4dbddbf1b9def5065d894078 to your computer and use it in GitHub Desktop.
Save felipec/811711cb4dbddbf1b9def5065d894078 to your computer and use it in GitHub Desktop.
Simple scanl implementation
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