Module: Immutable::Foldable
Instance Method Summary collapse
-
#length ⇒ Integer
(also: #size)
Returns the number of elements in
self
. -
#product ⇒ #*
Computes the product of the numbers in
self
. -
#sum ⇒ #+
Computes the sum of the numbers in
self
.
Instance Method Details
#length ⇒ Integer Also known as: size
Returns the number of elements in self
. May be zero.
6 7 8 |
# File 'lib/immutable/foldable.rb', line 6 def length foldl(0) { |x, y| x + 1 } end |
#product ⇒ #*
Computes the product of the numbers in self
.
25 26 27 |
# File 'lib/immutable/foldable.rb', line 25 def product foldl(1, &:*) end |
#sum ⇒ #+
Computes the sum of the numbers in self
.
18 19 20 |
# File 'lib/immutable/foldable.rb', line 18 def sum foldl(0, &:+) end |