product
The
product function computes the product of the numbers of a
structure.
Examples
Basic usage:
>>> product []
1
>>> product [42]
42
>>> product [1..10]
3628800
>>> product [4.1, 2.0, 1.7]
13.939999999999998
>>> product [1..]
* Hangs forever *
The
product function computes the product of a finite list of
numbers.
>>> product []
1
>>> product [42]
42
>>> product [1..10]
3628800
>>> product [4.1, 2.0, 1.7]
13.939999999999998
>>> product [1..]
* Hangs forever *
Get the product of all values in the stream.
Subject to fusion
Compute the product of the elements of a
Producer
Computes the product of all elements
Stricter version of
product.
>>> product [1..10]
3628800
Fold a
Stream of numbers into their product with the return
value
mapped product :: Stream (Stream (Of Int)) m r -> Stream (Of Int) m r
The
product function computes the product of the numbers of a
structure.
O(n) Compute the produce of the elements
Examples
>>> import qualified Data.Vector as V
>>> V.product $ V.fromList [1,2,3,4 :: Int]
24
>>> V.product (V.empty :: V.Vector Int)
1
O(n) Compute the produce of the elements
Examples
>>> import qualified Data.Vector as V
>>> V.product $ V.fromList [1,2,3,4 :: Int]
24
>>> V.product (V.empty :: V.Vector Int)
1
O(n) Compute the produce of the elements
Examples
>>> import qualified Data.Vector.Storable as VS
>>> VS.product $ VS.fromList [1,2,3,4 :: Int]
24
>>> VS.product (VS.empty :: VS.Vector Int)
1
O(n) Compute the produce of the elements
Examples
>>> import qualified Data.Vector.Unboxed as VU
>>> VU.product $ VU.fromList [1,2,3,4 :: Int]
24
>>> VU.product (VU.empty :: VU.Vector Int)
1
product does not need a one for initialization
Determine the product of all elements of a stream of numbers. Returns
1 when the stream is empty.
product = Stream.fold Fold.product
Compute the product of a finite list of numbers.
\(Array16 xs) -> Array.product xs == product (Array.toList xs)
Stricter version of
product.
>>> product [1..10]
3628800
>>> product (Right 3)
...
• Do not use 'Foldable' methods on Either
Suggestions:
Instead of
for_ :: (Foldable t, Applicative f) => t a -> (a -> f b) -> f ()
use
whenJust :: Applicative f => Maybe a -> (a -> f ()) -> f ()
whenRight :: Applicative f => Either l r -> (r -> f ()) -> f ()
...
Instead of
fold :: (Foldable t, Monoid m) => t m -> m
use
maybeToMonoid :: Monoid m => Maybe m -> m
...
O(n) Compute the product of the elements.
O(n) Compute the product of the elements.
O(n) Compute the product of the elements.