Skip to content
Browse files

Traversal1, Fold1

  • Loading branch information...
1 parent 6722e43 commit cebbf42a64ef8616822531863d4ea42e4676c3a9 @ekmett committed Oct 1, 2013
Showing with 21 additions and 20 deletions.
  1. +5 −5 src/Control/Lens/Fold.hs
  2. +16 −15 src/Control/Lens/Type.hs
View
10 src/Control/Lens/Fold.hs
@@ -220,15 +220,15 @@ folded' :: Foldable f => Fold (f a) a
folded' f = coerce . getFolding . foldMap (Folding #. f)
{-# INLINE folded' #-}
--- | Form a 'RelevantFold' by repeating the input forever.
+-- | Form a 'Fold1' by repeating the input forever.
--
-- @
-- 'repeat' ≡ 'toListOf' 'repeated'
-- @
--
-- >>> timingOut $ 5^..taking 20 repeated
-- [5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5]
-repeated :: RelevantFold a a
+repeated :: Fold1 a a
repeated f a = as where as = f a .> as
{-# INLINE repeated #-}
@@ -247,7 +247,7 @@ replicated n0 f a = go n0 where
go n = m *> go (n - 1)
{-# INLINE replicated #-}
--- | Transform a non-empty 'Fold' into a 'RelevantFold' that loops over its elements over and over.
+-- | Transform a non-empty 'Fold' into a 'Fold1' that loops over its elements over and over.
--
-- >>> timingOut $ [1,2,3]^..taking 7 (cycled traverse)
-- [1,2,3,1,2,3,1]
@@ -270,12 +270,12 @@ unfolded f g b0 = go b0 where
Nothing -> noEffect
{-# INLINE unfolded #-}
--- | @x '^.' 'iterated' f@ returns an infinite 'RelevantFold' of repeated applications of @f@ to @x@.
+-- | @x '^.' 'iterated' f@ returns an infinite 'Fold1' of repeated applications of @f@ to @x@.
--
-- @
-- 'toListOf' ('iterated' f) a ≡ 'iterate' f a
-- @
-iterated :: (a -> a) -> RelevantFold a a
+iterated :: (a -> a) -> Fold1 a a
iterated f g a0 = go a0 where
go a = g a .> go (f a)
{-# INLINE iterated #-}
View
31 src/Control/Lens/Type.hs
@@ -28,27 +28,27 @@ module Control.Lens.Type
-- * Lenses, Folds and Traversals
, Lens, Lens'
, Traversal, Traversal'
- , RelevantTraversal, RelevantTraversal'
+ , Traversal1, Traversal1'
, Setter, Setter'
, Getter, Fold
- , RelevantFold
+ , Fold1
, Action, MonadicFold, RelevantMonadicFold
-- * Indexed
, IndexedLens, IndexedLens'
, IndexedTraversal, IndexedTraversal'
- , IndexedRelevantTraversal, IndexedRelevantTraversal'
+ , IndexedTraversal1, IndexedTraversal1'
, IndexedSetter, IndexedSetter'
, IndexedGetter, IndexedFold
- , IndexedRelevantFold
+ , IndexedFold1
, IndexedAction, IndexedMonadicFold
, IndexedRelevantMonadicFold
-- * Index-Preserving
, IndexPreservingLens, IndexPreservingLens'
, IndexPreservingTraversal, IndexPreservingTraversal'
- , IndexPreservingRelevantTraversal, IndexPreservingRelevantTraversal'
+ , IndexPreservingTraversal1, IndexPreservingTraversal1'
, IndexPreservingSetter, IndexPreservingSetter'
, IndexPreservingGetter, IndexPreservingFold
- , IndexPreservingRelevantFold
+ , IndexPreservingFold1
, IndexPreservingAction, IndexPreservingMonadicFold
, IndexPreservingRelevantMonadicFold
-- * Common
@@ -192,8 +192,8 @@ type Traversal s t a b = forall f. Applicative f => (a -> f b) -> s -> f t
-- @
type Traversal' s a = Traversal s s a a
-type RelevantTraversal s t a b = forall f. Apply f => (a -> f b) -> s -> f t
-type RelevantTraversal' s a = RelevantTraversal s s a a
+type Traversal1 s t a b = forall f. Apply f => (a -> f b) -> s -> f t
+type Traversal1' s a = Traversal1 s s a a
-- | Every 'IndexedTraversal' is a valid 'Control.Lens.Traversal.Traversal' or
-- 'Control.Lens.Fold.IndexedFold'.
@@ -209,8 +209,8 @@ type IndexedTraversal i s t a b = forall p f. (Indexable i p, Applicative f) =>
-- @
type IndexedTraversal' i s a = IndexedTraversal i s s a a
-type IndexedRelevantTraversal i s t a b = forall p f. (Indexable i p, Apply f) => p a (f b) -> s -> f t
-type IndexedRelevantTraversal' i s a = IndexedRelevantTraversal i s s a a
+type IndexedTraversal1 i s t a b = forall p f. (Indexable i p, Apply f) => p a (f b) -> s -> f t
+type IndexedTraversal1' i s a = IndexedTraversal1 i s s a a
-- | An 'IndexPreservingLens' leaves any index it is composed with alone.
type IndexPreservingTraversal s t a b = forall p f. (Conjoined p, Applicative f) => p a (f b) -> p s (f t)
@@ -220,8 +220,8 @@ type IndexPreservingTraversal s t a b = forall p f. (Conjoined p, Applicative f)
-- @
type IndexPreservingTraversal' s a = IndexPreservingTraversal s s a a
-type IndexPreservingRelevantTraversal s t a b = forall p f. (Conjoined p, Apply f) => p a (f b) -> p s (f t)
-type IndexPreservingRelevantTraversal' s a = IndexPreservingRelevantTraversal s s a a
+type IndexPreservingTraversal1 s t a b = forall p f. (Conjoined p, Apply f) => p a (f b) -> p s (f t)
+type IndexPreservingTraversal1' s a = IndexPreservingTraversal1 s s a a
------------------------------------------------------------------------------
-- Setters
@@ -466,9 +466,10 @@ type IndexedFold i s a = forall p f. (Indexable i p, Contravariant f, Applicati
-- 'IndexedFold', or 'IndexedLens' yields an 'IndexedFold' respectively.
type IndexPreservingFold s a = forall p f. (Conjoined p, Contravariant f, Applicative f) => p a (f a) -> p s (f s)
-type RelevantFold s a = forall f. (Contravariant f, Apply f) => (a -> f a) -> s -> f s
-type IndexedRelevantFold i s a = forall p f. (Indexable i p, Contravariant f, Apply f) => p a (f a) -> s -> f s
-type IndexPreservingRelevantFold s a = forall p f. (Conjoined p, Contravariant f, Apply f) => p a (f a) -> p s (f s)
+-- | A relevant Fold (aka 'Fold1') has one or more targets.
+type Fold1 s a = forall f. (Contravariant f, Apply f) => (a -> f a) -> s -> f s
+type IndexedFold1 i s a = forall p f. (Indexable i p, Contravariant f, Apply f) => p a (f a) -> s -> f s
+type IndexPreservingFold1 s a = forall p f. (Conjoined p, Contravariant f, Apply f) => p a (f a) -> p s (f s)
-------------------------------------------------------------------------------
-- Actions

0 comments on commit cebbf42

Please sign in to comment.
Something went wrong with that request. Please try again.