@@ -5,10 +5,16 @@ import Prelude
55import Control.Comonad (class Comonad )
66import Control.Extend (class Extend )
77import Control.Lazy as CL
8-
8+ import Data.Foldable (class Foldable , foldMap , foldl , foldr )
9+ import Data.FoldableWithIndex (class FoldableWithIndex )
910import Data.Functor.Invariant (class Invariant , imapF )
11+ import Data.FunctorWithIndex (class FunctorWithIndex )
1012import Data.HeytingAlgebra (implies , ff , tt )
1113import Data.Monoid (class Monoid , mempty )
14+ import Data.Semigroup.Foldable (class Foldable1 , fold1Default )
15+ import Data.Semigroup.Traversable (class Traversable1 )
16+ import Data.Traversable (class Traversable , traverse )
17+ import Data.TraversableWithIndex (class TraversableWithIndex )
1218
1319-- | `Lazy a` represents lazily-computed values of type `a`.
1420-- |
@@ -75,6 +81,34 @@ instance booleanAlgebraLazy :: BooleanAlgebra a => BooleanAlgebra (Lazy a)
7581instance functorLazy :: Functor Lazy where
7682 map f l = defer \_ -> f (force l)
7783
84+ instance functorWithIndexLazy :: FunctorWithIndex Unit Lazy where
85+ mapWithIndex f = map $ f unit
86+
87+ instance foldableLazy :: Foldable Lazy where
88+ foldr f z l = f (force l) z
89+ foldl f z l = f z (force l)
90+ foldMap f l = f (force l)
91+
92+ instance foldableWithIndexLazy :: FoldableWithIndex Unit Lazy where
93+ foldrWithIndex f = foldr $ f unit
94+ foldlWithIndex f = foldl $ f unit
95+ foldMapWithIndex f = foldMap $ f unit
96+
97+ instance foldable1Lazy :: Foldable1 Lazy where
98+ foldMap1 f l = f (force l)
99+ fold1 = fold1Default
100+
101+ instance traversableLazy :: Traversable Lazy where
102+ traverse f l = defer <<< const <$> f (force l)
103+ sequence l = defer <<< const <$> force l
104+
105+ instance traversableWithIndexLazy :: TraversableWithIndex Unit Lazy where
106+ traverseWithIndex f = traverse $ f unit
107+
108+ instance traversable1Lazy :: Traversable1 Lazy where
109+ traverse1 f l = defer <<< const <$> f (force l)
110+ sequence1 l = defer <<< const <$> force l
111+
78112instance invariantLazy :: Invariant Lazy where
79113 imap = imapF
80114
0 commit comments