summaryrefslogtreecommitdiff
path: root/libraries/base/Data/Bifoldable1.hs
blob: 9e0521a9bd56f8dc8652a33336512bac91ddc258 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
-- |
-- Copyright: Edward Kmett, Oleg Grenrus
-- License: BSD-3-Clause
--

{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE Safe              #-}

module Data.Bifoldable1 where

import Control.Applicative (Const (..))
import Data.Bifoldable     (Bifoldable (..))
import Data.Semigroup      (Arg (..), Semigroup (..))
import Prelude             (Either (..), id)

class Bifoldable t => Bifoldable1 t where
     bifold1 :: Semigroup m => t m m -> m
     bifold1 = bifoldMap1 id id
     {-# INLINE bifold1 #-}

     bifoldMap1 :: Semigroup m => (a -> m) -> (b -> m) -> t a b -> m

instance Bifoldable1 Arg where
    bifoldMap1 f g (Arg a b) = f a <> g b

instance Bifoldable1 Either where
    bifoldMap1 f _ (Left a) = f a
    bifoldMap1 _ g (Right b) = g b
    {-# INLINE bifoldMap1 #-}

instance Bifoldable1 (,) where
    bifoldMap1 f g (a, b) = f a <> g b
    {-# INLINE bifoldMap1 #-}

instance Bifoldable1 ((,,) x) where
    bifoldMap1 f g (_,a,b) = f a <> g b
    {-# INLINE bifoldMap1 #-}

instance Bifoldable1 ((,,,) x y) where
    bifoldMap1 f g (_,_,a,b) = f a <> g b
    {-# INLINE bifoldMap1 #-}

instance Bifoldable1 ((,,,,) x y z) where
    bifoldMap1 f g (_,_,_,a,b) = f a <> g b
    {-# INLINE bifoldMap1 #-}

instance Bifoldable1 Const where
    bifoldMap1 f _ (Const a) = f a
    {-# INLINE bifoldMap1 #-}