Sum package:lens

Sum (Left q) = 2*q
Sum (Right q) = 2*q+1
Calculate the Sum of every number targeted by a Fold.
>>> sumOf both (5,6)
11

>>> sumOf folded [1,2,3,4]
10

>>> sumOf (folded.both) [(1,2),(3,4)]
10

>>> import Data.Data.Lens

>>> sumOf biplate [(1::Int,[]),(2,[(3::Int,4::Int)])] :: Int
10
sumsumOf folded
This operation may be more strict than you would expect. If you want a lazier version use ala Sum . foldMapOf
sumOf _1 :: Num a => (a, b) -> a
sumOf (folded . _1) :: (Foldable f, Num a) => f (a, b) -> a
sumOf :: Num a => Getter s a     -> s -> a
sumOf :: Num a => Fold s a       -> s -> a
sumOf :: Num a => Lens' s a      -> s -> a
sumOf :: Num a => Iso' s a       -> s -> a
sumOf :: Num a => Traversal' s a -> s -> a
sumOf :: Num a => Prism' s a     -> s -> a
The sum of a collection of actions, generalizing concatOf.
>>> asumOf both ("hello","world")
"helloworld"
>>> asumOf each (Nothing, Just "hello", Nothing)
Just "hello"
asumasumOf folded
asumOf :: Alternative f => Getter s (f a)     -> s -> f a
asumOf :: Alternative f => Fold s (f a)       -> s -> f a
asumOf :: Alternative f => Lens' s (f a)      -> s -> f a
asumOf :: Alternative f => Iso' s (f a)       -> s -> f a
asumOf :: Alternative f => Traversal' s (f a) -> s -> f a
asumOf :: Alternative f => Prism' s (f a)     -> s -> f a
The sum of a collection of actions, generalizing concatOf.
>>> msumOf both ("hello","world")
"helloworld"
>>> msumOf each (Nothing, Just "hello", Nothing)
Just "hello"
msummsumOf folded
msumOf :: MonadPlus m => Getter s (m a)     -> s -> m a
msumOf :: MonadPlus m => Fold s (m a)       -> s -> m a
msumOf :: MonadPlus m => Lens' s (m a)      -> s -> m a
msumOf :: MonadPlus m => Iso' s (m a)       -> s -> m a
msumOf :: MonadPlus m => Traversal' s (m a) -> s -> m a
msumOf :: MonadPlus m => Prism' s (m a)     -> s -> m a
A dual of lensProduct: a prism sum. The law
preview l (review l b) ≡ Just b
breaks with
>>> let badPrism :: Prism' (Maybe Char) (Either Char Char); badPrism = prismSum _Just _Just

>>> preview badPrism (review badPrism (Right 'x'))
Just (Left 'x')
We put in Right value, but get back Left. Are you looking for without?
The natural numbers are isomorphic to disjoint sums of natural numbers embedded as evens or odds.
N = 2*N