|
1 | 1 | -- | This module defines common lenses and prisms. |
2 | 2 |
|
3 | | -module Data.Lens.Common where |
4 | | - |
5 | | -import Prelude (Unit(), unit, const, ($), (<<<)) |
6 | | - |
7 | | -import Data.Either (Either(..), either) |
8 | | -import Data.Lens.Internal.Void (Void(), absurd) |
9 | | -import Data.Lens.Lens (Lens(), LensP(), lens) |
10 | | -import Data.Lens.Prism (Prism(), prism) |
11 | | -import Data.Maybe (Maybe(..), maybe) |
12 | | -import Data.Tuple (Tuple(..)) |
13 | | - |
14 | | --- | Prism for the `Nothing` constructor of `Maybe`. |
15 | | -_Nothing :: forall a b. Prism (Maybe a) (Maybe b) Unit Unit |
16 | | -_Nothing = prism (const Nothing) $ maybe (Right unit) (const $ Left Nothing) |
17 | | - |
18 | | --- | Prism for the `Just` constructor of `Maybe`. |
19 | | -_Just :: forall a b. Prism (Maybe a) (Maybe b) a b |
20 | | -_Just = prism Just $ maybe (Left Nothing) Right |
21 | | - |
22 | | --- | Prism for the `Left` constructor of `Either`. |
23 | | -_Left :: forall a b c. Prism (Either a c) (Either b c) a b |
24 | | -_Left = prism Left $ either Right (Left <<< Right) |
25 | | - |
26 | | --- | Prism for the `Right` constructor of `Either`. |
27 | | -_Right :: forall a b c. Prism (Either c a) (Either c b) a b |
28 | | -_Right = prism Right $ either (Left <<< Left) Right |
29 | | - |
30 | | --- | Lens for the first component of a `Tuple`. |
31 | | -_1 :: forall a b c. Lens (Tuple a c) (Tuple b c) a b |
32 | | -_1 = lens (\(Tuple a _) -> a) \(Tuple _ c) b -> Tuple b c |
33 | | - |
34 | | --- | Lens for the second component of a `Tuple`. |
35 | | -_2 :: forall a b c. Lens (Tuple c a) (Tuple c b) a b |
36 | | -_2 = lens (\(Tuple _ a) -> a) \(Tuple c _) b -> Tuple c b |
37 | | - |
38 | | --- | There is a `Unit` in everything. |
39 | | -united :: forall a. LensP a Unit |
40 | | -united = lens (const unit) const |
41 | | - |
42 | | --- | There is everything in `Void`. |
43 | | -devoid :: forall a. LensP Void a |
44 | | -devoid = lens absurd const |
| 3 | +module Data.Lens.Common |
| 4 | + ( module Data.Lens.Lens.Tuple |
| 5 | + , module Data.Lens.Lens.Unit |
| 6 | + , module Data.Lens.Lens.Void |
| 7 | + , module Data.Lens.Prism.Either |
| 8 | + , module Data.Lens.Prism.Maybe |
| 9 | + ) where |
| 10 | + |
| 11 | +import Data.Lens.Lens.Tuple |
| 12 | +import Data.Lens.Lens.Unit |
| 13 | +import Data.Lens.Lens.Void |
| 14 | +import Data.Lens.Prism.Either |
| 15 | +import Data.Lens.Prism.Maybe |
0 commit comments