Skip to content

Commit f56a74e

Browse files
authored
Merge pull request serokell#262 from serokell/dk318/serokell#182-deprecate-microlens
[serokell#182] Deprecate `microlens` and `microlens-mtl` dependencies
2 parents e4ed7f5 + 1f64f96 commit f56a74e

File tree

4 files changed

+118
-7
lines changed

4 files changed

+118
-7
lines changed

CHANGES.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ Unreleased
1212
_Migration guide:_ use `safeHead` directly with functions from
1313
`Universum.Container` instead.
1414

15+
* [#182](https://github.com/serokell/universum/issues/182):
16+
Deprecate `microlens` and `microlens-mtl` dependencies.
17+
1518
1.7.3
1619
=====
1720

src/Universum.hs

Lines changed: 113 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{-# LANGUAGE Trustworthy #-}
2+
{-# LANGUAGE RankNTypes #-}
23

34
{- | Main module that reexports all functionality allowed to use
45
without importing any other modules. Just add next lines to your
@@ -80,8 +81,26 @@ module Universum
8081
, module Universum.VarArg
8182

8283
-- * Lenses
83-
, module Lens.Micro
84-
, module Lens.Micro.Mtl
84+
, Lens
85+
, Lens'
86+
, Traversal
87+
, Traversal'
88+
, over
89+
, set
90+
, (%~)
91+
, (.~)
92+
, (^.)
93+
, (^..)
94+
, (^?)
95+
, _1
96+
, _2
97+
, _3
98+
, _4
99+
, _5
100+
, preuse
101+
, preview
102+
, use
103+
, view
85104
) where
86105

87106
import Universum.Applicative
@@ -104,6 +123,95 @@ import Universum.TypeOps
104123
import Universum.VarArg
105124

106125
-- Lenses
107-
import Lens.Micro (Lens, Lens', Traversal, Traversal', over, set, (%~), (&), (.~), (<&>), (^.),
108-
(^..), (^?), _1, _2, _3, _4, _5)
109-
import Lens.Micro.Mtl (preuse, preview, use, view)
126+
import qualified Lens.Micro (ASetter, Getting, over, set, (%~), (.~), (^.),
127+
(^..), (^?), _1, _2, _3, _4, _5)
128+
import qualified Lens.Micro.Mtl (preuse, preview, use, view)
129+
import Lens.Micro.Internal (Field1, Field2, Field3, Field4, Field5)
130+
131+
{-# DEPRECATED
132+
Lens
133+
, Lens'
134+
, Traversal
135+
, Traversal'
136+
, over
137+
, set
138+
, (%~)
139+
, (.~)
140+
, (^.)
141+
, (^..)
142+
, (^?)
143+
, _1
144+
, _2
145+
, _3
146+
, _4
147+
, _5
148+
, preuse
149+
, preview
150+
, use
151+
, view
152+
"Use corresponding function from 'lens' or 'microlens' package"
153+
#-}
154+
155+
type Lens s t a b = forall f. Functor f => (a -> f b) -> s -> f t
156+
type Lens' s a = Lens s s a a
157+
158+
type Traversal s t a b = forall f. Applicative f => (a -> f b) -> s -> f t
159+
type Traversal' s a = Traversal s s a a
160+
161+
over :: Lens.Micro.ASetter s t a b -> (a -> b) -> s -> t
162+
over = Lens.Micro.over
163+
164+
set :: Lens.Micro.ASetter s t a b -> b -> s -> t
165+
set = Lens.Micro.set
166+
167+
(%~) :: Lens.Micro.ASetter s t a b -> (a -> b) -> s -> t
168+
(%~) = (Lens.Micro.%~)
169+
170+
infixr 4 %~
171+
172+
(.~) :: Lens.Micro.ASetter s t a b -> b -> s -> t
173+
(.~) = (Lens.Micro..~)
174+
175+
infixr 4 .~
176+
177+
(^.) :: s -> Lens.Micro.Getting a s a -> a
178+
(^.) = (Lens.Micro.^.)
179+
180+
infixl 8 ^.
181+
182+
(^..) :: s -> Lens.Micro.Getting (Endo [a]) s a -> [a]
183+
(^..) = (Lens.Micro.^..)
184+
185+
infixl 8 ^..
186+
187+
(^?) :: s -> Lens.Micro.Getting (First a) s a -> Maybe a
188+
(^?) = (Lens.Micro.^?)
189+
190+
infixl 8 ^?
191+
192+
_1 :: Field1 s t a b => Lens s t a b
193+
_1 = Lens.Micro._1
194+
195+
_2 :: Field2 s t a b => Lens s t a b
196+
_2 = Lens.Micro._2
197+
198+
_3 :: Field3 s t a b => Lens s t a b
199+
_3 = Lens.Micro._3
200+
201+
_4 :: Field4 s t a b => Lens s t a b
202+
_4 = Lens.Micro._4
203+
204+
_5 :: Field5 s t a b => Lens s t a b
205+
_5 = Lens.Micro._5
206+
207+
preuse :: MonadState s m => Lens.Micro.Getting (First a) s a -> m (Maybe a)
208+
preuse = Lens.Micro.Mtl.preuse
209+
210+
preview :: MonadReader s m => Lens.Micro.Getting (First a) s a -> m (Maybe a)
211+
preview = Lens.Micro.Mtl.preview
212+
213+
use :: MonadState s m => Lens.Micro.Getting a s a -> m a
214+
use = Lens.Micro.Mtl.use
215+
216+
view :: MonadReader s m => Lens.Micro.Getting a s a -> m a
217+
view = Lens.Micro.Mtl.view

src/Universum/Function.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ module Universum.Function
66
( module Data.Function
77
) where
88

9-
import Data.Function (const, fix, flip, id, on, ($), (.))
9+
import Data.Function (const, fix, flip, id, on, ($), (.), (&))

src/Universum/Functor/Reexport.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ module Universum.Functor.Reexport
1212

1313
import Control.Arrow ((&&&))
1414
import Data.Bifunctor (Bifunctor (..))
15-
import Data.Functor (Functor (..), void, ($>), (<$>))
15+
import Data.Functor (Functor (..), void, ($>), (<$>), (<&>))
1616
import Data.Functor.Compose (Compose (..))
1717
import Data.Functor.Identity (Identity (..))

0 commit comments

Comments
 (0)