@@ -16,14 +16,13 @@ import Prelude
16
16
import Data.Either (Either (..), either )
17
17
import Data.Foldable (class Foldable , foldMap )
18
18
import Data.HeytingAlgebra (tt , ff )
19
- import Data.Lens.Internal.Forget (Forget (..))
19
+ import Data.Lens.Internal.Forget (Forget (..))
20
20
import Data.Lens.Types (Fold , Fold' ) as ExportTypes
21
21
import Data.Lens.Types (IndexedFold , Fold , Optic' , Indexed (..))
22
22
import Data.List (List (..), (:))
23
23
import Data.Maybe (Maybe (..), maybe )
24
24
import Data.Maybe.First (First (..))
25
25
import Data.Maybe.Last (Last (..))
26
- import Data.Monoid (class Monoid , mempty )
27
26
import Data.Monoid.Additive (Additive (..))
28
27
import Data.Monoid.Conj (Conj (..))
29
28
import Data.Monoid.Disj (Disj (..))
@@ -47,18 +46,18 @@ infixl 8 previewOn as ^?
47
46
48
47
-- | Folds all foci of a `Fold` to one. Note that this is the same as `view`.
49
48
foldOf :: forall s t a b . Fold a s t a b -> s -> a
50
- foldOf p = foldMapOf p id
49
+ foldOf p = foldMapOf p identity
51
50
52
51
-- | Maps and then folds all foci of a `Fold`.
53
52
foldMapOf :: forall s t a b r . Fold r s t a b -> (a -> r ) -> s -> r
54
53
foldMapOf = under Forget
55
54
56
55
-- | Right fold over a `Fold`.
57
- foldrOf :: forall s t a b r . Fold (Endo r ) s t a b -> (a -> r -> r ) -> r -> s -> r
56
+ foldrOf :: forall s t a b r . Fold (Endo ( -> ) r ) s t a b -> (a -> r -> r ) -> r -> s -> r
58
57
foldrOf p f r = flip unwrap r <<< foldMapOf p (Endo <<< f)
59
58
60
59
-- | Left fold over a `Fold`.
61
- foldlOf :: forall s t a b r . Fold (Dual (Endo r )) s t a b -> (r -> a -> r ) -> r -> s -> r
60
+ foldlOf :: forall s t a b r . Fold (Dual (Endo ( -> ) r )) s t a b -> (r -> a -> r ) -> r -> s -> r
62
61
foldlOf p f r = flip unwrap r <<< unwrap <<< foldMapOf p (Dual <<< Endo <<< flip f)
63
62
64
63
-- | Whether all foci of a `Fold` satisfy a predicate.
@@ -71,11 +70,11 @@ anyOf p f = unwrap <<< foldMapOf p (Disj <<< f)
71
70
72
71
-- | The conjunction of all foci of a `Fold`.
73
72
andOf :: forall s t a b . HeytingAlgebra a => Fold (Conj a ) s t a b -> s -> a
74
- andOf p = allOf p id
73
+ andOf p = allOf p identity
75
74
76
75
-- | The disjunction of all foci of a `Fold`.
77
76
orOf :: forall s t a b . HeytingAlgebra a => Fold (Disj a ) s t a b -> s -> a
78
- orOf p = anyOf p id
77
+ orOf p = anyOf p identity
79
78
80
79
-- | Whether a `Fold` contains a given element.
81
80
elemOf :: forall s t a b . Eq a => Fold (Disj Boolean ) s t a b -> a -> s -> Boolean
@@ -106,25 +105,25 @@ lastOf :: forall s t a b. Fold (Last a) s t a b -> s -> Maybe a
106
105
lastOf p = unwrap <<< foldMapOf p (Last <<< Just )
107
106
108
107
-- | The maximum of all foci of a `Fold`, if there is any.
109
- maximumOf :: forall s t a b . Ord a => Fold (Endo (Maybe a )) s t a b -> s -> Maybe a
108
+ maximumOf :: forall s t a b . Ord a => Fold (Endo (-> ) ( Maybe a )) s t a b -> s -> Maybe a
110
109
maximumOf p = foldrOf p (\a -> Just <<< maybe a (max a)) Nothing where
111
110
max a b = if a > b then a else b
112
111
113
112
-- | The minimum of all foci of a `Fold`, if there is any.
114
- minimumOf :: forall s t a b . Ord a => Fold (Endo (Maybe a )) s t a b -> s -> Maybe a
113
+ minimumOf :: forall s t a b . Ord a => Fold (Endo (-> ) ( Maybe a )) s t a b -> s -> Maybe a
115
114
minimumOf p = foldrOf p (\a -> Just <<< maybe a (min a)) Nothing where
116
115
min a b = if a < b then a else b
117
116
118
117
-- | Find the first focus of a `Fold` that satisfies a predicate, if there is any.
119
- findOf :: forall s t a b . Fold (Endo (Maybe a )) s t a b -> (a -> Boolean ) -> s -> Maybe a
118
+ findOf :: forall s t a b . Fold (Endo (-> ) ( Maybe a )) s t a b -> (a -> Boolean ) -> s -> Maybe a
120
119
findOf p f = foldrOf p (\a -> maybe (if f a then Just a else Nothing ) Just ) Nothing
121
120
122
121
-- | Sequence the foci of a `Fold`, pulling out an `Applicative`, and ignore
123
122
-- | the result. If you need the result, see `sequenceOf` for `Traversal`s.
124
123
sequenceOf_
125
124
:: forall f s t a b
126
125
. Applicative f
127
- => Fold (Endo (f Unit )) s t (f a ) b
126
+ => Fold (Endo (-> ) ( f Unit )) s t (f a ) b
128
127
-> s
129
128
-> f Unit
130
129
sequenceOf_ p = flip unwrap (pure unit) <<< foldMapOf p \f -> Endo (f *> _)
@@ -133,18 +132,18 @@ sequenceOf_ p = flip unwrap (pure unit) <<< foldMapOf p \f -> Endo (f *> _)
133
132
traverseOf_
134
133
:: forall f s t a b r
135
134
. Applicative f
136
- => Fold (Endo (f Unit )) s t a b
135
+ => Fold (Endo (-> ) ( f Unit )) s t a b
137
136
-> (a -> f r )
138
137
-> s
139
138
-> f Unit
140
139
traverseOf_ p f = foldrOf p (\a fu -> void (f a) *> fu) (pure unit)
141
140
142
141
-- | Collects the foci of a `Fold` into a list.
143
- toListOf :: forall s t a b . Fold (Endo (List a )) s t a b -> s -> List a
142
+ toListOf :: forall s t a b . Fold (Endo (-> ) ( List a )) s t a b -> s -> List a
144
143
toListOf p = foldrOf p (:) Nil
145
144
146
145
-- | Synonym for `toListOf`, reversed.
147
- toListOfOn :: forall s t a b . s -> Fold (Endo (List a )) s t a b -> List a
146
+ toListOfOn :: forall s t a b . s -> Fold (Endo (-> ) ( List a )) s t a b -> List a
148
147
toListOfOn s p = toListOf p s
149
148
150
149
infixl 8 toListOfOn as ^..
@@ -163,7 +162,7 @@ filtered f =
163
162
right >>>
164
163
dimap
165
164
(\x -> if f x then Right x else Left x)
166
- (either id id )
165
+ (either identity identity )
167
166
168
167
-- | Replicates the elements of a fold.
169
168
replicated :: forall a b t r . Monoid r => Int -> Fold r a b a t
@@ -198,7 +197,7 @@ ifoldMapOf p f = unwrap $ p $ Indexed $ Forget (uncurry f)
198
197
-- | Right fold over an `IndexedFold`.
199
198
ifoldrOf
200
199
:: forall i s t a b r
201
- . IndexedFold (Endo r ) i s t a b
200
+ . IndexedFold (Endo ( -> ) r ) i s t a b
202
201
-> (i -> a -> r -> r )
203
202
-> r
204
203
-> s
@@ -208,7 +207,7 @@ ifoldrOf p f r = flip unwrap r <<< ifoldMapOf p (\i -> Endo <<< f i)
208
207
-- | Left fold over an `IndexedFold`.
209
208
ifoldlOf
210
209
:: forall i s t a b r
211
- . IndexedFold (Dual (Endo r )) i s t a b
210
+ . IndexedFold (Dual (Endo ( -> ) r )) i s t a b
212
211
-> (i -> r -> a -> r )
213
212
-> r
214
213
-> s
@@ -242,7 +241,7 @@ ianyOf p f = unwrap <<< ifoldMapOf p (\i -> Disj <<< f i)
242
241
-- | there is any.
243
242
ifindOf
244
243
:: forall i s t a b
245
- . IndexedFold (Endo (Maybe a )) i s t a b
244
+ . IndexedFold (Endo (-> ) ( Maybe a )) i s t a b
246
245
-> (i -> a -> Boolean )
247
246
-> s
248
247
-> Maybe a
@@ -255,15 +254,15 @@ ifindOf p f =
255
254
-- | Collects the foci of an `IndexedFold` into a list.
256
255
itoListOf
257
256
:: forall i s t a b
258
- . IndexedFold (Endo (List (Tuple i a ))) i s t a b
257
+ . IndexedFold (Endo (-> ) ( List (Tuple i a ))) i s t a b
259
258
-> s
260
259
-> List (Tuple i a )
261
260
itoListOf p = ifoldrOf p (\i x xs -> Tuple i x : xs) Nil
262
261
263
262
-- | Traverse the foci of an `IndexedFold`, discarding the results.
264
263
itraverseOf_
265
264
:: forall i f s t a b r . (Applicative f )
266
- => IndexedFold (Endo (f Unit )) i s t a b
265
+ => IndexedFold (Endo (-> ) ( f Unit )) i s t a b
267
266
-> (i -> a -> f r )
268
267
-> s
269
268
-> f Unit
@@ -272,7 +271,7 @@ itraverseOf_ p f = ifoldrOf p (\i a fu -> void (f i a) *> fu) (pure unit)
272
271
-- | Flipped version of `itraverseOf_`.
273
272
iforOf_
274
273
:: forall i f s t a b r . (Applicative f )
275
- => IndexedFold (Endo (f Unit )) i s t a b
274
+ => IndexedFold (Endo (-> ) ( f Unit )) i s t a b
276
275
-> s
277
276
-> (i -> a -> f r )
278
277
-> f Unit
0 commit comments