Merge pull request #26 from cocreature/sumproduct
Export strict versions of sum and product
This commit is contained in:
@@ -1,3 +1,8 @@
|
||||
0.1.9
|
||||
====
|
||||
|
||||
* Make `sum` and `product` strict
|
||||
|
||||
0.1.8
|
||||
=====
|
||||
|
||||
|
||||
+12
-1
@@ -6,16 +6,19 @@ module List (
|
||||
ordNub,
|
||||
sortOn,
|
||||
list,
|
||||
product,
|
||||
sum
|
||||
) where
|
||||
|
||||
import Data.List (sortBy)
|
||||
import Data.Maybe (Maybe(..))
|
||||
import Data.Ord (Ord, comparing)
|
||||
import Data.Foldable (Foldable, foldr)
|
||||
import Data.Foldable (Foldable, foldr, foldl')
|
||||
import Data.Function ((.))
|
||||
import Data.Functor (fmap)
|
||||
import Control.Monad (return)
|
||||
import qualified Data.Set as Set
|
||||
import GHC.Num (Num, (+))
|
||||
|
||||
head :: (Foldable f) => f a -> Maybe a
|
||||
head = foldr (\x _ -> return x) Nothing
|
||||
@@ -37,3 +40,11 @@ list :: [b] -> (a -> b) -> [a] -> [b]
|
||||
list def f xs = case xs of
|
||||
[] -> def
|
||||
_ -> fmap f xs
|
||||
|
||||
{-# INLINE product #-}
|
||||
product :: (Foldable f, Num a) => f a -> a
|
||||
product = foldl' (+) 1
|
||||
|
||||
{-# INLINE sum #-}
|
||||
sum :: (Foldable f, Num a) => f a -> a
|
||||
sum = foldl' (+) 0
|
||||
|
||||
@@ -95,6 +95,8 @@ import Data.Traversable as X
|
||||
import Data.Foldable as X hiding (
|
||||
foldr1
|
||||
, foldl1
|
||||
, product
|
||||
, sum
|
||||
)
|
||||
import Semiring as X
|
||||
import Data.Functor.Identity as X
|
||||
|
||||
Reference in New Issue
Block a user