@@ -22,27 +22,21 @@ module Data.Foldable
2222 , minimumBy
2323 ) where
2424
25- import Control.Applicative ( class Applicative , pure )
26- import Control.Apply ((*>))
25+ import Prelude
26+
2727import Control.Plus (class Plus , alt , empty )
2828
29- import Data.BooleanAlgebra (class BooleanAlgebra , not )
30- import Data.Eq (class Eq , (==))
31- import Data.Function (id , flip , (<<<))
3229import Data.Maybe (Maybe (..))
3330import Data.Maybe.First (First (..))
3431import Data.Maybe.Last (Last (..))
35- import Data.Monoid (class Monoid , mempty , (<>) )
32+ import Data.Monoid (class Monoid , mempty )
3633import Data.Monoid.Additive (Additive (..))
37- import Data.Monoid.Conj (Conj (..), runConj )
38- import Data.Monoid.Disj (Disj (..), runDisj )
39- import Data.Monoid.Dual (Dual (..), runDual )
40- import Data.Monoid.Endo (Endo (..), runEndo )
34+ import Data.Monoid.Conj (Conj (..))
35+ import Data.Monoid.Disj (Disj (..))
36+ import Data.Monoid.Dual (Dual (..))
37+ import Data.Monoid.Endo (Endo (..))
4138import Data.Monoid.Multiplicative (Multiplicative (..))
42- import Data.Ord (class Ord , compare )
43- import Data.Ordering (Ordering (..))
44- import Data.Semiring (class Semiring , one , (*), zero , (+))
45- import Data.Unit (Unit , unit )
39+ import Data.Newtype (alaF , unwrap )
4640
4741-- | `Foldable` represents data structures which can be _folded_.
4842-- |
@@ -76,7 +70,7 @@ foldrDefault
7670 -> b
7771 -> f a
7872 -> b
79- foldrDefault c u xs = runEndo (foldMap (Endo <<< c) xs) u
73+ foldrDefault c u xs = unwrap (foldMap (Endo <<< c) xs) u
8074
8175-- | A default implementation of `foldl` using `foldMap`.
8276-- |
@@ -89,8 +83,7 @@ foldlDefault
8983 -> b
9084 -> f a
9185 -> b
92- foldlDefault c u xs =
93- runEndo (runDual (foldMap (Dual <<< Endo <<< flip c) xs)) u
86+ foldlDefault c u xs = unwrap (unwrap (foldMap (Dual <<< Endo <<< flip c) xs)) u
9487
9588-- | A default implementation of `foldMap` using `foldr`.
9689-- |
@@ -234,24 +227,24 @@ intercalate sep xs = (foldl go { init: true, acc: mempty } xs).acc
234227-- | The conjunction of all the values in a data structure. When specialized
235228-- | to `Boolean`, this function will test whether all of the values in a data
236229-- | structure are `true`.
237- and :: forall a f . (Foldable f , BooleanAlgebra a ) => f a -> a
230+ and :: forall a f . (Foldable f , HeytingAlgebra a ) => f a -> a
238231and = all id
239232
240233-- | The disjunction of all the values in a data structure. When specialized
241234-- | to `Boolean`, this function will test whether any of the values in a data
242235-- | structure is `true`.
243- or :: forall a f . (Foldable f , BooleanAlgebra a ) => f a -> a
236+ or :: forall a f . (Foldable f , HeytingAlgebra a ) => f a -> a
244237or = any id
245238
246239-- | `all f` is the same as `and <<< map f`; map a function over the structure,
247240-- | and then get the conjunction of the results.
248- all :: forall a b f . (Foldable f , BooleanAlgebra b ) => (a -> b ) -> f a -> b
249- all p = runConj <<< foldMap ( Conj <<< p)
241+ all :: forall a b f . (Foldable f , HeytingAlgebra b ) => (a -> b ) -> f a -> b
242+ all p = alaF Conj foldMap p
250243
251244-- | `any f` is the same as `or <<< map f`; map a function over the structure,
252245-- | and then get the disjunction of the results.
253- any :: forall a b f . (Foldable f , BooleanAlgebra b ) => (a -> b ) -> f a -> b
254- any p = runDisj <<< foldMap ( Disj <<< p)
246+ any :: forall a b f . (Foldable f , HeytingAlgebra b ) => (a -> b ) -> f a -> b
247+ any p = alaF Disj foldMap p
255248
256249-- | Find the sum of the numeric values in a data structure.
257250sum :: forall a f . (Foldable f , Semiring a ) => f a -> a
0 commit comments